我在UpdatePanel里面的GridView中有一个CheckBox(ItemTemplate)。 当用户单击btnAjax按钮时,我想在代码后面获取CheckBox值。怎么做?
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="dgvUserGroup" runat="server">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnAjax" runat="server" Text="Button" OnClick="btnAjax_Click" />
</ContentTemplate>
</asp:UpdatePanel>
protected void Page_Load(object sender, EventArgs e)
{
dgvUserGroup.DataSource = someDatatable;
dgvUserGroup.DataBind();
}
protected void btnAjax_Click(object sender, EventArgs e)
{
try
{
DataTable dtbTest = (DataTable)dgvUserGroup.DataSource;
//how can i get the checkbox value here?
}
catch (Exception ex)
{
}
}
答案 0 :(得分:3)
protected void btnAjax_Click(object sender, EventArgs e)
{
try
{
foreach (GridViewRow gvRow in dgvUserGroup.Rows)
{
CheckBox chk = (CheckBox)gvRow.FindControl("chkRow");
Boolean chkVal = chk.Checked;//Here You can get the value
}
}
catch (Exception ex)
{
}
}