html 代码
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
Width="366px" CellPadding="4"
ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID"
InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="tag" HeaderText="标志" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<HeaderTemplate>
</HeaderTemplate>
</asp:TemplateField> </Columns> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="审核" /></div>
cs代码
protected void Button3_Click(object sender, EventArgs e)
{
int i;
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
con.Open();
for (i = 0; i < GridView1.Rows.Count;i++ )
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
if (cbox != null)
{ string uid = GridView1.Rows[i].Cells[0].Text.ToString();
string cmdtext1 = "update table1 set tag='" + "5" + "' where id=" + uid;
SqlCommand cmd2 = new SqlCommand(cmdtext1, con);
cmd2.ExecuteNonQuery();
}
}
GridView1.EditIndex = -1;
BindData();
}
点button3的时候,在gridview上的数据全部都更新了,我的要求是更新checkbox被选上的行,帮忙看看是什么原因,谢谢
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
Width="366px" CellPadding="4"
ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID"
InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="tag" HeaderText="标志" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<HeaderTemplate>
</HeaderTemplate>
</asp:TemplateField> </Columns> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="审核" /></div>
cs代码
protected void Button3_Click(object sender, EventArgs e)
{
int i;
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
con.Open();
for (i = 0; i < GridView1.Rows.Count;i++ )
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
if (cbox != null)
{ string uid = GridView1.Rows[i].Cells[0].Text.ToString();
string cmdtext1 = "update table1 set tag='" + "5" + "' where id=" + uid;
SqlCommand cmd2 = new SqlCommand(cmdtext1, con);
cmd2.ExecuteNonQuery();
}
}
GridView1.EditIndex = -1;
BindData();
}
点button3的时候,在gridview上的数据全部都更新了,我的要求是更新checkbox被选上的行,帮忙看看是什么原因,谢谢
解决方案 »
- Microsoft.Jet.OleDb.12.0 提供程序要怎么解决
- sql视图问题求助
- C#中 有没有一种方法 导出 一个类的所有方法名 和 注释 到记事本中 或其他地方
- GridView的页码显示位置问题
- C#操作注册表的小小问题。。。
- 两天速成的方法?
- 为什么文本框获取焦点后的事件不停的在循环?
- 请教XMLDocument的Load机制
- 数学符号怎么输入。。。。。
- 主窗体设置messagebox后关闭时发生异常
- C Shape如何"修改并显示"每一个当前激活的窗体的标题...
- C#的Hook实例...大家帮帮修改一下我所要的效果,功能...因为我对Hook不了解...去MSDN查了也不了解怎么用...
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox cbox = (CheckBox)gr.Cells[4].FindControl("chkSelect");
if (cbox.Checked)
{
string uid = GridView1.Rows[i].Cells[0].Text.ToString();
string cmdtext1 = "update table1 set tag='" + "5" + "' where id=" + uid;
SqlCommand cmd2 = new SqlCommand(cmdtext1, con);
cmd2.ExecuteNonQuery();
}
}