views:

1816

answers:

2

Hi,

I'm looking to be able to click on a gridview row in order to select a row rather than use the select link.

I have the code below which make the row clickable and act like a hyperlink.....

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

    If (e.Row.RowType = DataControlRowType.DataRow) Then
        e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';this.style.textDecoration='underline';")
        e.Row.Attributes.Add("onmouseout", "this.style.textDecoration='none';")
        e.Row.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(Me.GridView1, "Select$" + e.Row.RowIndex.ToString()))
    End If

    End Sub

....but then I get the error message:

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Anyone know how to overcome this?

Thanks,

A: 

Adrian Godong's comment is correct. The easiest way to correct this is to set the GridView to still generate the Select LinkButton, but set its Visible property to false. Finally, set the onclick event to fire a virtual click on the Select LinkButton. This way, the ASP.NET event will come directly from the Select button and you will therefore not be caught be an invalid postback security check.

JoshJordan
A: 

Thanks for help had found the answer another way...rather than use the visibility property I set the display property to none and everything worked as is...

<asp:CommandField ShowSelectButton="True" ItemStyle-CssClass="HiddenColumn" HeaderStyle-CssClass="HiddenColumn"/>


.HiddenColumn{display:none;}
thegunner