开发者

Passing Control Id from Linkbutton in a gridview

开发者_C百科How do I pass the Control ID in a gridview that is derived from a stored procedure into a variable. I will use the variable to pass into the database later on to return some results. Thanks.


var controlId = ((LinkButton)gridView1.Rows[0].FindControl("lbName")).Id;

Are you trying to do something like the above?

Update
You can use the OnSelectedIndex event of the GridView to find the row that was select.

  void GridView_SelectedIndexChanged(Object sender, EventArgs e)
  {
    // Get the currently selected row using the SelectedRow property.
    GridViewRow row = CustomersGridView.SelectedRow;

    var controlId = ((LinkButton)row.FindControl("lbName")).Id;
  }


I tend to use the CommandName and CommandArgument fields with LinkButtons in a GridView.

The CommandName represents the name of the command, so that you can have more than one linkbutton that do different things and the CommandArgument is the Database ID or other point of reference for the command.

You need to subscribe to the RowCommand event handler on the GridView

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜