需求:在gridview中添加一列radio 并能将其选中的行删除!
解决方案 »
- net抽奖程序!
- 为datalist里的HyperLink循环赋值时最后一个HyperLink赋不了值
- 弹出一个模式窗口,改变其中的内容,要让后面的页面内容也同时更新怎么弄?
- 100分收购一个SQL语句???请大家帮帮忙!!!
- Winform下的Treeview为什么没有SelectedNode.value? 如果我要根据节点取Id什么的怎么取呢?
- C#里边有没什么函数能计算出两个DATETIME之间相差时间的?
- 关于上传下载的问题。
- 关于适配器,我在查询分析器里运行是好用的,但是有错误提示必须声明变量 '@bdate'。
- 怎么做这个SQL
- 如何获取前台的名字
- aspx有个gridview控件,控件中有2万行数据,我的buttonclick事件后,控件中的数据是否上传?
- javascript调用.cs文件中的有参数方法??
{
if (((RadioButton)gr.FindControl("RadioButton1")).Checked)
{}
}
<asp:TemplateField HeaderText="选中状态">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" OnCheckedChanged="SelectAll" runat="server" Text="全选" AutoPostBack="true"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cb" runat="server"/>
</ItemTemplate>
</asp:TemplateField> //删除选中项
for (int i = 0; i < Gridview1.Rows.Count; i++)
{
CheckBox _cb = (CheckBox)Gridview1.Rows[i].FindControl("cb");
if (_cb.Checked)
{
int _no = int.Parse(Gridview1.DataKeys[i].Value.ToString());
//执行删除
}
} //全选/反选
protected void SelectAll(object sender, EventArgs e)
{
bool isChecked = ((CheckBox)(Gridview1.HeaderRow.Cells[0].FindControl("chkAll"))).Checked;
foreach (GridViewRow gvRow in Gridview1.Rows)
{
((CheckBox)(Gridview1.Cells[0].FindControl("cb"))).Checked = isChecked;
}
}
{
if (((RadioButton)gr.FindControl("RadioButton1")).Checked)
{
sqlConnection con = new SqlConnection("server=local;database=Northwind;uid=sa;pwd=123");
con.Open();
string deleteid = GridView1.DataKeys[e.RowIndex].Value.ToString();
string cmdtext = "delete from orders where orderid='" + deleteid + "'";
SqlCommand cmd = new SqlCommand(cmdtext, con);
try
{
cmd.ExecuteNonQuery();
Response.Write("<script>alert('删除成功');</script>");
}
catch
{
return;
}
banddelete();
con.Close();
}
}