开发者

Finding CheckBox control in Gridview

I have two template fields in my data gridview. One template field is a CheckBox with ID="AttendanceCheckBox" and the other template field is a Label which is bind to the StudentID field in the Student Table.

What is the C# code for finding the CheckBox in开发者_如何学Go the Gridview? Also I need to add the value (StudentID) in the Template Field Label to a different database table how would I go about achieving this?

Appreciate all the help. Thanks in advance!


See, the following code part to add a checkbox to the grid view

<asp:TemplateField HeaderText="Email Alert">
                        <HeaderStyle Width="100px" HorizontalAlign="Left"></HeaderStyle>
                        <ItemTemplate>
                            <asp:CheckBox ID="chkEmailAlert1" runat="server" Visible="true" Enabled="false" Checked='<%# DataBinder.Eval(Container,"DataItem.EmailAlert") %>' />
                            <asp:CheckBox ID="chkEmailAlert" runat="server" Visible="false" Enabled="true" Checked='<%# DataBinder.Eval(Container,"DataItem.EmailAlert") %>' />
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center" />
                    </asp:TemplateField>

and see the following code to find the Checkbox control in the grid view.

 foreach (System.Web.UI.WebControls.GridViewRow row in EscalationGrid.Rows) {
if ((((CheckBox)row.FindControl("chkEmailAlert")).Checked == true)) {
    Arr_EmailAlert(i) = "True";
} else {
    Arr_EmailAlert(i) = "False";
}
if ((((CheckBox)row.FindControl("chkSMSAlert")).Checked == true)) {
    Arr_SmsAlert(i) = "True";
} else {
    Arr_SmsAlert(i) = "False";
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜