当我签入gridview 时,我想更新数据。在我从复选框中获取值但我的代码仅从数据库返回数据之前。我检查后想要当前值。
代码隐藏:-
protected void chkSelected_CheckedChanged(object sender, EventArgs e)
{
for (int rowIndex = 0; rowIndex < GridView1.Rows.Count; rowIndex++)
{
if (Convert.ToString(GridView1.Rows[rowIndex].Cells[4].Text) != "")
{
Response.Write("true");
}
else
{
Response.Write("fasle");
}
}
}
设计规范:-
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
CellPadding="4" GridLines="None" ForeColor="#333333" Font-Size="Smaller"
AutoGenerateColumns="False">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="LevelID" HeaderText="ลำดับข้อ" ReadOnly="True"
ItemStyle-Width="50" >
</asp:BoundField>
<asp:BoundField DataField="LevelDesc" HeaderText="คำถาม" ReadOnly="True"
ItemStyle-Width="250" >
</asp:BoundField>
<asp:BoundField DataField="ChoiceID" HeaderText="ข้อย่อย" ReadOnly="True"
ItemStyle-Width="50" >
</asp:BoundField>
<asp:BoundField DataField="ChoiceDesc" HeaderText="คำถามย่อย" ReadOnly="True"
ItemStyle-Width="400" >
</asp:BoundField>
<asp:TemplateField HeaderText="ใช่">
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" Checked='<%# Eval("Selected").ToString().Equals("True") %>'
AutoPostBack="true" OnCheckedChanged="chkSelected_CheckedChanged" CssClass="chkBox" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#0000CD" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>