GridView的RowCommand事件中取得行索引
2008-08-06 13:34
489 查看
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;
}
}
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;
}
}
相关文章推荐
- GridView的RowCommand事件中取得行索引
- ASP.NET 2.0 GridView的RowCommand事件中取得行索引
- GridView的RowCommand事件中取得行索引 技巧
- GridView的RowCommand事件中取得行索引 技巧
- 【转】GridView的RowCommand事件中取得行索引
- GridView的RowCommand事件中取得行索引
- GridView的RowCommand事件中取得行索引
- GridView的RowCommand事件中取得行索引
- GridView中模版列使用RowCommand事件如何得到当前列的行索引?
- GridView的RowCommand事件中取得行索引
- GridView的RowCommand事件中取得控件值
- GridView_RowCommand事件中取得GridViewRow
- 在 GridView的RowCommand事件中取得相应的行号,主键值与某行某列的值
- GridView的RowCommand事件中取得行索引
- ASP.NET 2.0 GridView RowCommand 事件取得行号
- Gridview中的RowCommand事件中如何获得该列的索引?
- ASP.NET 2.0 GridView的RowCommand事件中取得行索
- ASP.NET 2.0 GridView的RowCommand事件中取得行索
- 在GridView的RowCommand事件中取得相应的行号,主键值与某行某列的值
- LinkButton及RowCommand事件中获取Gridview中行索引并此行变色