2024年3月29日发(作者:)
()GridView 在RowCommand事件中获取当前行数据
//获取当前行
GridViewRow gvr = (GridViewRow)((Control)dSource).;
//获取当前行中的某一列中的TextBox控件
TextBox txtJobsName = (TextBox)[2].FindControl("txtJobsName");
第二种方法:页面没有绑定CommandArgument
int index=32(dArgument);
GridViewRow row =[index];
----------------------------------------------------------------------------------------------------------------------
第一种方式,取得点击的行号,主键值,某行中指定列的值,如下:
protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e)
{
//获取当前点击前的行号,说明:ImageButton
放的按钮为ImageButton,用户可以根据放置的控件不同而不同。
int index = ((GridViewRow)((ImageButton)(dSource)).).RowIndex;
//获取当前选点击行的主键值
string key = ys[index].ng();
//获取当前点击行,某列的值
string id = [index].Cells[1].Text;
/*
补充一下,因为我在上面的前台代码中放了CommandArgument='<%#
Eval("ProductID") %>',ProductID为数据库中的主键,所以得到主键值也可以如下:string
strProductId = ng();
*/
// 有了上面的操作,以下操作就方便了
if (dName == "manage")
{
//.......
}
}
因为我
第二种方式:
//在前台代码中,不要 CommandArgument='<%# Eval("ProductID") %>' 这个代码,即
去掉这个,然后,下面操作:
protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (dName == "manage")
{
int index = 32(dArgument);
string key = ys[index].ng();
(key);
}
}
//行数据绑定
protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e == w)
{
ImageButton imgBtn = new ImageButton ();
imgBtn = (ImageButton )[6].FindControl("imgBtnManage");//自己清
楚,此ImageButton模板列,你放在GridView中的第几列。
imgBtn .CommandArgument = ng();
}
}


发布评论