那位朋友 可以帮我看看 我想通过添加一列按钮(buttonfield)实现批准用户注册,其中状态表示用户是否被批准,如果状态是0就是待批准的,如果状态是1,表明管理员已经批准了,现在,我不知如何编写buttonfield事件,来获取当前行的id,然后修改数据库,我看了很多的帖子,但是我都没有运行起来,希望大家帮帮我,谢谢了.......!
我用的是:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "a")//a 表示buttonfield的相关CommandName名称为a
{ datastring w = new datastring();//创建连接数据库字符串
using (SqlConnection coon = new SqlConnection(w.coonstring))
{
coon.Open();
........................ 我想问下这里如何实现获得修改当前选中行id(编号),然后修改批准状态的
coon.Close();
}
ShowDB();//重新绑定数据库
}
}
我用的是:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "a")//a 表示buttonfield的相关CommandName名称为a
{ datastring w = new datastring();//创建连接数据库字符串
using (SqlConnection coon = new SqlConnection(w.coonstring))
{
coon.Open();
........................ 我想问下这里如何实现获得修改当前选中行id(编号),然后修改批准状态的
coon.Close();
}
ShowDB();//重新绑定数据库
}
}
解决方案 »
- JS引用放在updatepanel内,出现的一些异常!
- 我在自己的机子部署了一个asp.net网站,。。。(在线等)
- 我想通过点击“选择文件”按钮后弹出下面的对话框,不知代码该怎么写
- 数据库触发器问题 ,在线等,求正解
- 一个Asp.Net程序中,在shtml页面里面怎样访问C#中的方法?
- 关于ASP.NET的定时器,是不是网站没有访问就不起作用?
- 如何不在页面加载时,就使数据源控件绑定到GridView控件
- DATAGRID的SELECTEDINDEX 问题
- 初学。NET ,这个类型怎么转换啊 ???
- 哪里有Solpartmenu这个菜单控件下载啊
- 急急急,请教个关于倒计时的功能。
- 弱问:如何在新窗口中显示出查询结果?
string str = grd.DataKeys[intRow].Value.ToString();
{
if (e.CommandName == "save_btn") //如果是OpenRow按纽
{
//string sql;
int iIndex = Convert.ToInt32(e.CommandArgument);
string nID = this.GridView2.DataKeys[iIndex].Value.ToString();
strsql88 = "select * from stone_out where storage_code='" + nID + "'";
/* SqlCommand sqlcom = new SqlCommand(sql, con);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();*/
GridView1.EditIndex = -1;
Databind88(strsql88);
}
<asp:ButtonField ButtonType="Button" DataTextField="storage_code"
HeaderText="查看" Text="按钮" CommandName="save_btn"
DataTextFormatString="查看"/>
这个是必须的<%@ Page Language="C#" EnableViewState="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("id", typeof(System.Int32)));
dt.Columns.Add(new System.Data.DataColumn("Name", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("Count", typeof(System.Double)));
dt.Columns.Add(new System.Data.DataColumn("CreateDate", typeof(System.DateTime))); System.Random rd = new System.Random();
for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr[0] = i + i;
dr[1] = "【孟子E章】" + i.ToString();
dr[2] = System.Math.Ceiling(rd.NextDouble() * 1000);
dr[3] = DateTime.Now.AddDays(rd.Next(100) - rd.Next(100));
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
} protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "a")
{
Response.Write(GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand" DataKeyNames="id">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="a" Text="点击测试得到该行 id 的值" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
http://dotnet.aspx.cc/article/0e8fdeb4-c461-4f44-9933-672a7510097a/read.aspx
的方法,更适合编辑、修改数据