关于将数据中的值作为复选框 数据绑定 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CheckBoxList?items.add(数据库返回值); 复选框实现绑定数据库并删除、更新信息//获取数据库信息加载到页面public void GV_DataBind() { string sqlstr = "select * from tb_inf "; sqlcon = new SqlConnection(strCon); SqlDataAdapter da = new SqlDataAdapter(sqlstr, sqlcon); DataSet ds = new DataSet(); sqlcon.Open(); da.Fill(ds, "tb_inf"); sqlcon.Close(); this.GridView1.DataSource = ds; this.GridView1.DataKeyNames = new string[] { "id" }; this.GridView1.DataBind(); if (GridView1.Rows.Count > 0) { return;//有数据,不要处理 } else//显示表头并显示没有数据的提示信息 { StrHelper.GridViewHeader(GridView1); }}//CodeGo.net///绑定控件实现删除操作protected void btnDeleteMore_Click(object sender, EventArgs e) { sqlcon = new SqlConnection(strCon);//创建数据库连接 SqlCommand sqlcom;//创建命令对象变量 for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//循环遍历GridView控件每一项 { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("cbSingleOrMore");//查找嵌套在GridView控件中的单选框 if (cbox.Checked == true)//如果操作为选中状态 { string strSql = "delete from tb_inf where id=@id";//定义带参数的删除语句 if (sqlcon.State.Equals(ConnectionState.Closed)) sqlcon.Open();//打开数据加连接 sqlcom = new SqlCommand(strSql, sqlcon);//创建执行删除操作的命令对象 SqlParameter prame = new SqlParameter("@id", SqlDbType.Int, 4);//定义参数 sqlcom.Parameters.Add(prame);//添加参数 sqlcom.Parameters["@id"].Value = GridView1.DataKeys[i].Value.ToString();//参数赋值 if (sqlcom.ExecuteNonQuery() > 0)//判断删除是否成功 { StrHelper.Alert("删除成功!"); } else { StrHelper.Alert("删除失败!"); } sqlcon.Close();//关闭数据库连接 } } GV_DataBind();//重新绑定数据控件 } protected void btnDeleteMore_Load(object sender, EventArgs e) { ((Button)sender).Attributes["onclick"] = "return confirm('您确定要删除吗?')"; }//对数据库数据更新操作 protected void btnUpdateTime_Click(object sender, EventArgs e) { sqlcon = new SqlConnection(strCon);//创建数据库连接 SqlCommand sqlcom;//创建命令对象变量 for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//循环遍历GridView控件每一项 { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("cbSingleOrMore"); if (cbox.Checked == true) { string strSql = "Update tb_inf set issueDate=@UpdateTime where id=@id"; if (sqlcon.State.Equals(ConnectionState.Closed)) sqlcon.Open();//打开数据库连接 sqlcom = new SqlCommand(strSql, sqlcon); SqlParameter[] prams = { new SqlParameter("@UpdateTime",SqlDbType.DateTime), new SqlParameter("@id",SqlDbType.Int,4) }; prams[0].Value = DateTime.Now; prams[1].Value = GridView1.DataKeys[i].Value; foreach (SqlParameter parameter in prams) { sqlcom.Parameters.Add(parameter); } if (sqlcom.ExecuteNonQuery() > 0) { StrHelper.Alert("更新成功!"); } else { StrHelper.Alert("更新失败!"); } sqlcon.Close(); } } GV_DataBind(); } 怎么申请开通传图片权限 请教!如何由c#代码生成完整安装文件 wpf怎么实现文件列表功能 如何為ListView排序時設定Colunn的索引? vs 2005 winform 我程序修改了程序但他一直执行以前的 C#金额 数字格式问题!!盼回复! 菜鸟问菜问题 散分了!留言就有分! C#编译问题 急求帮助~!~!~! 求助:求 网页论坛和聊天室 建设的相关代码 C# 局域网传输,用组播实现 关于程序开机自启动的问题
items.add(数据库返回值);
//获取数据库信息加载到页面
public void GV_DataBind()
{
string sqlstr = "select * from tb_inf ";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter da = new SqlDataAdapter(sqlstr, sqlcon);
DataSet ds = new DataSet();
sqlcon.Open();
da.Fill(ds, "tb_inf");
sqlcon.Close();
this.GridView1.DataSource = ds;
this.GridView1.DataKeyNames = new string[] { "id" };
this.GridView1.DataBind();
if (GridView1.Rows.Count > 0)
{
return;//有数据,不要处理
}
else//显示表头并显示没有数据的提示信息
{
StrHelper.GridViewHeader(GridView1);
}
}//CodeGo.net/
//绑定控件实现删除操作
protected void btnDeleteMore_Click(object sender, EventArgs e)
{
sqlcon = new SqlConnection(strCon);//创建数据库连接
SqlCommand sqlcom;//创建命令对象变量
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//循环遍历GridView控件每一项
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("cbSingleOrMore");//查找嵌套在GridView控件中的单选框
if (cbox.Checked == true)//如果操作为选中状态
{
string strSql = "delete from tb_inf where id=@id";//定义带参数的删除语句
if (sqlcon.State.Equals(ConnectionState.Closed))
sqlcon.Open();//打开数据加连接
sqlcom = new SqlCommand(strSql, sqlcon);//创建执行删除操作的命令对象
SqlParameter prame = new SqlParameter("@id", SqlDbType.Int, 4);//定义参数
sqlcom.Parameters.Add(prame);//添加参数
sqlcom.Parameters["@id"].Value = GridView1.DataKeys[i].Value.ToString();//参数赋值
if (sqlcom.ExecuteNonQuery() > 0)//判断删除是否成功
{
StrHelper.Alert("删除成功!");
}
else
{
StrHelper.Alert("删除失败!");
}
sqlcon.Close();//关闭数据库连接
}
}
GV_DataBind();//重新绑定数据控件
}
protected void btnDeleteMore_Load(object sender, EventArgs e)
{
((Button)sender).Attributes["onclick"] = "return confirm('您确定要删除吗?')";
}
//对数据库数据更新操作
protected void btnUpdateTime_Click(object sender, EventArgs e)
{
sqlcon = new SqlConnection(strCon);//创建数据库连接
SqlCommand sqlcom;//创建命令对象变量
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//循环遍历GridView控件每一项
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("cbSingleOrMore");
if (cbox.Checked == true)
{
string strSql = "Update tb_inf set issueDate=@UpdateTime where id=@id";
if (sqlcon.State.Equals(ConnectionState.Closed))
sqlcon.Open();//打开数据库连接
sqlcom = new SqlCommand(strSql, sqlcon);
SqlParameter[] prams = {
new SqlParameter("@UpdateTime",SqlDbType.DateTime),
new SqlParameter("@id",SqlDbType.Int,4)
};
prams[0].Value = DateTime.Now;
prams[1].Value = GridView1.DataKeys[i].Value;
foreach (SqlParameter parameter in prams)
{
sqlcom.Parameters.Add(parameter);
}
if (sqlcom.ExecuteNonQuery() > 0)
{
StrHelper.Alert("更新成功!");
}
else
{
StrHelper.Alert("更新失败!");
}
sqlcon.Close();
}
}
GV_DataBind();
}