thegunner
thegunner

Reputation: 7153

asp.net gridview - select row

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,

Upvotes: 0

Views: 14411

Answers (3)

ynnok
ynnok

Reputation: 246

You could also use "RegisterForEventValidation".

Check this: RegisterForEventValidation .net 3.5 gridview row, how to?

Upvotes: 0

thegunner
thegunner

Reputation: 7153

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;} 

Upvotes: 7

JoshJordan
JoshJordan

Reputation: 12975

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.

Upvotes: 0

Related Questions