c# gridview row click

后端 未结 9 1916
野的像风
野的像风 2020-12-01 09:34

When I click on a row in my GridView, I want to go to a other page with the ID I get from the database.

In my RowCreated event I have the following line:

         


        
相关标签:
9条回答
  • 2020-12-01 10:16

    Can your ID be related to the data item displayed in the gridview?

    If so you can use e.Row.DataItem, and cast it to whatever type it is.

    0 讨论(0)
  • 2020-12-01 10:20
    protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e)  
    {     
     if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridViewRow gvr = e.Row;
                string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();         
                gvr.Attributes.Add("OnClick", "javascript:location.href='Default.aspx?id=" + abc + "'");
            }         
    
       }  
    }  
    
    0 讨论(0)
  • 2020-12-01 10:22

    You can use the RowCommand event of the grid view for it. In your button/link where you wnat to set the click on, set the CommandName and CommandArgument, which you can accees at the EventArgs paramter of the event method.

    0 讨论(0)
提交回复
热议问题