gridview里的checkbox问题
gridview里显示一列标题列,点击标题列字段,数据表其他内容就显示在TEXBOX里,为什么加上CHEKBOX,删除功能就不起作用了呢,如果只是显示标题列,不做数据表内容显示在TEXBOX这个功能,就能成功删除,逐句调试时,发现是string sql = "delete from news where biaoti =“”为空,是什么原因呢?
protected void Page_Load(object sender, EventArgs e)
{
string conn = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
SqlConnection con = new SqlConnection(conn);
con.Open();
DataSet myDataSet = new DataSet();
SqlDataAdapter myCommand = new SqlDataAdapter("newsList", con);
//填充DataSet
myCommand.Fill(myDataSet);
//关闭链接
GridView1.DataSource = myDataSet;
//绑定
GridView1.DataBind();
Button1.Attributes.Add("onclick", "return confirm('您确定要删除所有选定记录吗?');");
}
protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < this.GridView1.Rows.Count; i++)
{
if (((CheckBox)this.GridView1.Rows[i].Cells[1].FindControl("CheckBox1")).Checked == true)
{
string conn = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
SqlConnection con = new SqlConnection(conn);
con.Open();
DataSet ds = new DataSet();
string sql = "delete from news where biaoti ='" + this.GridView1.Rows[i].Cells[1].Text.ToString() + "'";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sql, con);
da.Fill(ds, "news");
con.Close();
}
}
string conn1 = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
SqlConnection con1 = new SqlConnection(conn1);
con1.Open();
DataSet myDataSet = new DataSet();
SqlDataAdapter myCommand = new SqlDataAdapter("newsList", con1);
//填充DataSet
myCommand.Fill(myDataSet);
//关闭链接
GridView1.DataSource = myDataSet;
//绑定
GridView1.DataBind();
con1.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedDataKey["biaoti"].ToString();
TextBox2.Text = GridView1.SelectedDataKey["fabuzhe"].ToString();
TextBox3.Text = GridView1.SelectedDataKey["shijian"].ToString();
TextBox4.Text = GridView1.SelectedDataKey["neirong"].ToString();
}
}
protected void Page_Load(object sender, EventArgs e)
{
string conn = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
SqlConnection con = new SqlConnection(conn);
con.Open();
DataSet myDataSet = new DataSet();
SqlDataAdapter myCommand = new SqlDataAdapter("newsList", con);
//填充DataSet
myCommand.Fill(myDataSet);
//关闭链接
GridView1.DataSource = myDataSet;
//绑定
GridView1.DataBind();
Button1.Attributes.Add("onclick", "return confirm('您确定要删除所有选定记录吗?');");
}
protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < this.GridView1.Rows.Count; i++)
{
if (((CheckBox)this.GridView1.Rows[i].Cells[1].FindControl("CheckBox1")).Checked == true)
{
string conn = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
SqlConnection con = new SqlConnection(conn);
con.Open();
DataSet ds = new DataSet();
string sql = "delete from news where biaoti ='" + this.GridView1.Rows[i].Cells[1].Text.ToString() + "'";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sql, con);
da.Fill(ds, "news");
con.Close();
}
}
string conn1 = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
SqlConnection con1 = new SqlConnection(conn1);
con1.Open();
DataSet myDataSet = new DataSet();
SqlDataAdapter myCommand = new SqlDataAdapter("newsList", con1);
//填充DataSet
myCommand.Fill(myDataSet);
//关闭链接
GridView1.DataSource = myDataSet;
//绑定
GridView1.DataBind();
con1.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedDataKey["biaoti"].ToString();
TextBox2.Text = GridView1.SelectedDataKey["fabuzhe"].ToString();
TextBox3.Text = GridView1.SelectedDataKey["shijian"].ToString();
TextBox4.Text = GridView1.SelectedDataKey["neirong"].ToString();
}
}
...全文
相关推荐
每周精选合集-活动资源
~ Gitee ~
传统企业负责人克服【部署生成式AI业务】困难的五大解决方案
启动AI战略需要时间、努力和大量专业技能和理解。在竞争对手纷纷启动自己的计划时,解决和应对这些挑战变得尤为重要。通过投资AI基础设施专业知识、从基础规划、加强数据管理和治理、采用新的运营策略以及实现自动化,传统企业可以顺利推进AI业务的部署,实现更高的投资回报和更强的市场竞争力。成功实施AI的最重要建议对正确的工具、合作伙伴和专业知识进行扎实的投资。AI是一项巨大的工作,但从一开始就发展基础和这些能力有助于你实现投资回报和更快的价值实现时间,显著降低业务风险,并提供在市场中取得成功所需的竞争优势。
医疗信创国产化替代目前面临哪些难题?如何利用国产虚拟化技术促进医院信创建设
业务系统众多,存在大量信创改造模糊地带,既有老系统,也有新系统,故障点多,管理难度高,IT人力资源不足,其对硬件的支撑能力也提出了越来越高的要求,由此造成硬件成本、管理成本以及能耗成本都非常高。
kali破解wifi之airmon-ng 工具利用
......
从零到一:高通QCS6490边缘AI开发板的Linux生态构建与实战避坑指南
本文详细介绍了在高通QCS6490边缘AI开发板上构建Linux生态系统的完整流程,包括开发环境准备、系统镜像构建与烧录、AI运行时环境配置、模型部署优化以及性能调试。重点解析了如何利用Hexagon DSP的高达12 TOPS AI算力,并提供了实战中的避坑指南和性能优化技巧,帮助开发者高效实现边缘AI应用从概念验证到产品落地的全过程。


