2011-04-20 74 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"; 
} 
}