2011-04-20 81 views
0

我的数据网格视图中有两个模板字段。一个模板字段是ID =“AttendanceCheckBox”的CheckBox,另一个模板字段是绑定到Student表中StudentID字段的Label。在Gridview中查找复选框控件

什么是在GridView中查找CheckBox的C#代码? 另外,我需要将模板字段标签中的值(StudentID)添加到不同的数据库表中,我将如何去实现此目的?

欣赏所有的帮助。提前致谢!

回答

0

看到,下面的代码部分的复选框添加到网格视图

<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> 

,看看下面的代码,以找到在网格视图CheckBox控件。

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"; 
} 
}