views:

65

answers:

2

So I made each row of a GridView clickable using this method:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString());
    }
}

So that when I click a row, the program redirects to Page1 via the GridView.SelectedRowChanged method.

Each row also contains some a HyperLink that is supposed to redirect to Page2. However, clicking on the HyperLink only redirects to Page1 because the SelectedRowChanged event fires first.

How do I redirect to the correct page when the HyperLink is clicked? Is it as simple as making the HyperLinks LinkButtons and executing the Click method?

+1  A: 

You have to check if the target control is an anchor, ignore postback execution. Check the following instance.

<div onclick="if(event.target.tagName != 'A') { alert('Foo'); }" style="width: 100px; height: 100px;">
    <a href="Default.aspx">Home</a>
</div>
Mehdi Golchin
A: 

Turns out it is as easy as making the HyperLinks LinkButtons and executing the Click method. Who knew?

Matthew Jones