LISTVIEW wpf
我查询表里的数据,在listview里列出来(这个已实现)现在另外一个button,对选中的某一行数据进行修改帮忙告诉我怎么实现吧,谢了,最好给我一个例子哦...
我查询表里的数据,在listview里列出来(这个已实现)
现在另外一个button,对选中的某一行数据进行修改
帮忙告诉我怎么实现吧,谢了,最好给我一个例子哦 展开
现在另外一个button,对选中的某一行数据进行修改
帮忙告诉我怎么实现吧,谢了,最好给我一个例子哦 展开
1个回答
展开全部
给你一段我用在 Gridview 中的代码,请参考
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandSource.GetType() != typeof(LinkButton))
{
return;
}
LinkButton Lb = (LinkButton)e.CommandSource; //CommandSource 属性,可以访问引发事件的按钮控件
string id = e.CommandArgument.ToString(); //这样就提取出来了 GroupId
Session["GroupId"] = id;
if (Lb.ID == "Del")
{
if (db1.getOneValueSqlStr("Select Count(*) From SMSUserGroup where GroupId=" + id) != "0")
{
LbErr.Text = "分组中存在用户,不能删除!";
LbErr.Visible = true;
}
else
{
string sqlStr = "Delete * From SMSGroup where GroupId=" + id;
db1.execSqlStr(sqlStr);
clearInput();
}
}
else if (Lb.ID == "Edit")
{
LbErr.Visible = false;
DataTable dt = new DataTable();
dt = db1.getDataTable("select * from SMSGroup where GroupId=" + id);
TBGroupName.Text = dt.Rows[0]["GroupName"].ToString();
BtAdd.Visible = false;
BtUpdate.Visible = true;
BtCancel.Visible = true;
}
GridView1.DataSource = GetDataTable(); ;
GridView1.DataBind();
}
具体修改可以用SQL指令完成
string sqlStr = "UPDATE SMSGroup SET GroupName = '" + TBGroupName.Text.Trim() + "' WHERE GroupId=" + Session["GroupId"];
db1.execSqlStr(sqlStr);
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandSource.GetType() != typeof(LinkButton))
{
return;
}
LinkButton Lb = (LinkButton)e.CommandSource; //CommandSource 属性,可以访问引发事件的按钮控件
string id = e.CommandArgument.ToString(); //这样就提取出来了 GroupId
Session["GroupId"] = id;
if (Lb.ID == "Del")
{
if (db1.getOneValueSqlStr("Select Count(*) From SMSUserGroup where GroupId=" + id) != "0")
{
LbErr.Text = "分组中存在用户,不能删除!";
LbErr.Visible = true;
}
else
{
string sqlStr = "Delete * From SMSGroup where GroupId=" + id;
db1.execSqlStr(sqlStr);
clearInput();
}
}
else if (Lb.ID == "Edit")
{
LbErr.Visible = false;
DataTable dt = new DataTable();
dt = db1.getDataTable("select * from SMSGroup where GroupId=" + id);
TBGroupName.Text = dt.Rows[0]["GroupName"].ToString();
BtAdd.Visible = false;
BtUpdate.Visible = true;
BtCancel.Visible = true;
}
GridView1.DataSource = GetDataTable(); ;
GridView1.DataBind();
}
具体修改可以用SQL指令完成
string sqlStr = "UPDATE SMSGroup SET GroupName = '" + TBGroupName.Text.Trim() + "' WHERE GroupId=" + Session["GroupId"];
db1.execSqlStr(sqlStr);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询