很多人在使用asp.net 2.0的gridview中的模板列时不知道如何获取当前行号,datagrid中是可以直接获得的.
在gridview中,事件的参数变成了GridViewCommandEnentArgs,我们可以数据绑定后给相应模板列控件指定事件参数,在处理其事件的时候就再获取出来
使用模板列时控件CommandName不要取与删除列和编辑、更新列相同的名字,如delete,否则会引发相应的事件
一个简单的事例如下:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="UpdateStatus")
{
string docid = GridView1.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].Text;
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btUpSts= (Button)e.Row.FindControl("bt_upsts");
btUpSts.CommandArgument = e.Row.RowIndex.ToString();
}
}
本文介绍在ASP.NET 2.0中如何使用GridView控件的模板列来获取当前行号,并通过一个具体示例展示了如何设置CommandArgument属性以实现这一功能。
158

被折叠的 条评论
为什么被折叠?



