c# gridview row click

Posted by Martijn on Stack Overflow See other posts from Stack Overflow or by Martijn
Published on 2008-12-01T15:50:29Z Indexed on 2010/04/06 2:43 UTC
Read the original article Hit count: 518

Filed under:
|
|
|

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:

e.Row.Attributes.Add("onClick", ClientScript.GetPostBackClientHyperlink(this.grdSearchResults, "Select$" + e.Row.RowIndex));

To prevent error messages i have this code:

protected override void Render(HtmlTextWriter writer)
    {
        // .NET will refuse to accept "unknown" postbacks for security reasons. Because of this we have to register all possible callbacks
        // This must be done in Render, hence the override
        for (int i = 0; i < grdSearchResults.Rows.Count; i++)
        {
            Page.ClientScript.RegisterForEventValidation(new System.Web.UI.PostBackOptions(grdSearchResults, "Select$" + i.ToString()));
        }
        // Do the standard rendering stuff
        base.Render(writer);
    }

My question is, how can i give a row a unique id (from the DB) and when i click the row, another page is opened (like clicking on a href) and that page can read the id.

Thnx

© Stack Overflow or respective owner

Related posts about c#

Related posts about gridview