GV里的e.CommandArgument没有任何参数
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToString() == "topstep ")
{
//向上移,Sort+1
if (e.CommandArgument != null&&e.CommandArgument.ToString()!= " ")
errmessage.Text = e.CommandArgument.ToString();
else
errmessage.Text = "没有参数 ";
//errmessage.Text = "11 ";
}
if (e.CommandName.ToString() == "bottomstep ")
{
//向下移,Sort-1
errmessage.Text = "22 ";
}
}
我以前一直都这样用的.但这次却取不到数据.前台显示为 "没有参数 "
郁闷了好几天,有人帮忙吗?!
------解决方案--------------------如果你用的是模版列,需要自己填充e.CommandArgument参数
在GridView1_RowCreated,把当前行索引赋给按钮的CommandArgument属性
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton totop ;
if (e.Row.RowType == DataControlRowType.DataRow)
{
totop = (LinkButton)e.Row.FindControl( "totop ");
if (totop != null)
{
if (totop.CommandName== "topstep ")
totop.CommandArgument = e.Row.RowIndex.ToString();
}
}
}