

Code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//如果是为数据行
{
ImageButton imgbtnup = (ImageButton)e.Row.Cells[1].FindControl(“btnMoveUp“);//找控件
imgbtnup.CommandArgument = e.Row.RowIndex.ToString();//设置与此BUTTON关联的命令参数
imgbtnup.Visible = e.Row.RowIndex != 0;
ImageButton imgbtndown = (ImageButton)e.Row.Cells[2].FindControl(“btnMoveDown“);
imgbtndown.CommandArgument = e.Row.RowIndex.ToString();
imgbtndown.Visible = e.Row.RowIndex != ((DataSet)((GridView)sender).DataSource).Tables[0].Rows.Count – 1;
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == “MoveUp“)
{
int index = Convert.ToInt32(e.CommandArgument);//取的行索引
DataKey key = this.GridView1.DataKeys[index];
string keyval = key.Value;//取得主键
}
else if (e.CommandName == “MoveDown“)
{
int index = Convert.ToInt32(e.CommandArgument);
DataKey key = this.GridView1.DataKeys[index];
string keyval = key.Value;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/111003.html原文链接:https://javaforall.net