e.CommandArgument的值是通过下面代码实现的,
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton linkButtonCInfo = (LinkButton)e.Row.FindControl("lbtnCInfo");
linkButtonCInfo.CommandArgument = e.Row.RowIndex.ToString();
}
}
或
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView drv;
drv = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (drv != null)
{
GridViewRow gvr = (GridViewRow)e.Row;
ImageButton imageBt = (ImageButton)gvr.FindControl("imagebt1");
imageBt.CommandArgument = e.Row.RowIndex.ToString();
}
}
}
这样就可以给自定义的按钮设定CommandArgument 值了.