Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey there,

i want to select a single row at a time by clicking on a gridview row.i am doing this under RowDataBound event --

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
               e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
               e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
           }
       }



but its not working.Its showing error - Invalid postback or callback argument.

thanks
Amit
Posted

Try using Page.ClientScript.GetPostBackEventReference instead of ClientScript.GetPostBackClientHyperlink

Have a look at this article: Developing a row-clickable GridView[^]
It's in VB.NET but concept is same.
 
Share this answer
 
this[^] might help you.
 
Share this answer
 
In the @Page directive use EnableEventValidation="false"

let me know whether it solves the problem or not
 
Share this answer
 
Comments
AmitChoudhary10 1-Mar-11 1:28am    
its not showing the Invalid postback or callback argument error now, and it also postbacks when i click the row but does'nt show whether the row is selected or selected.I mean row color does'nt change.
senguptaamlan 1-Mar-11 1:32am    
you need to do that from code behind..as it is getting post back so you can get which row is getting selected...based on that change the CSS Class of the selected row...besides this...if you want to do the thing without using post back use CallBack featutre to achieve the same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900