问题描述
我有一个模板领域的GridView。我在模板列添加一个复选框。自动回是真的为复选框。
I have a gridview with Template field. I add a checkbox in templatefield . Autopostback is true for checkbox .
我填的负载页面网格和creted列动态。
I fill grid in Load-page and creted column dynamic .
if (!IsPostBack)
{
FillGrid();
}
我使用更新面板
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<SharePoint:SPGridView ID="grid" AllowSorting="true" AllowFiltering="true" CssClass="ms-listviewtable"
runat="server" AutoGenerateColumns="false">
<RowStyle CssClass="ms-alternating" Height="10px" />
<Columns>
<asp:TemplateField>
<ItemTemplate >
<asp:CheckBox ID="select" runat="server"
OnCheckedChanged="select_CheckedChanged" AutoPostBack="true" />
<input id="Display" type="hidden" runat="server" />
<input id="itemID" type="hidden" runat="server" />
<asp:Image ID="icon" runat="server" Height="10px" Visible="false" />
</ItemTemplate>
<ItemStyle Width="35px" />
</asp:TemplateField>
<asp:TemplateField >
</asp:TemplateField>
</Columns>
</SharePoint:SPGridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="select" EventName="OnCheckedChanged" />
</Triggers>
</asp:UpdatePanel>
但显示错误:ID为控制'选择'不能为的UpdatePanel'UpdatePanel1'触发器被发现。
but show error :A control with ID 'select' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
我的问题是:当复选框的变化,页面刷新
My problem is : When checkbox is change, page refresh
我不希望以后checkedchange!刷新页面
推荐答案
所有你需要templetecolumn如下
First of all you need changes templetecolumn as below
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkselect" runat="server" />
<input id="Display" type="hidden" runat="server" />
<input id="itemID" type="hidden" runat="server" />
<asp:Image ID="imgicon" runat="server" Height="10px" Style="display: none;" ImageUrl="~/images/arrow_left.jpg" />
</ItemTemplate>
<ItemStyle Width="35px" />
</asp:TemplateField>
现在在服务器端code处理ItemDataBound事件
Now handle itemdatabound event in server side code
Protected Sub SPGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBanner.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim chkselect As CheckBox = e.Row.FindControl("chkselect")
Dim imgicon As Image = e.Row.FindControl("imgicon")
If chkselect IsNot Nothing Then
chkselect.Attributes.Add("onclick", "javascript:DoMyTask(this,'" + imgicon.ClientID + "')")
End If
End If
End Sub
现在在如下aspx页面中指定JavaScript函数。
Now specify JavaScript function in aspx page as below.
<script type="text/javascript" language="javascript">
function DoMyTask(obj, imgid) {
var objCheck = obj.checked;
var objimg = document.getElementById(imgid)
if (objCheck == true) {
objimg.style.display = "block";
//set more attributes over here
}
else {
objimg.style.display = "none";
//set more attributes over here
}
var count = $(":checkbox:checked").length;
alert('you have selected ' + count + ' Rows');
}
</script>
希望这会帮助你...编码快乐..
Hope this will help you...happy coding ..
这篇关于GridView控件不刷新的CheckedChanged后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!