Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I cannot seam to use this twice on my page to render two different gridviews on the same page works well with one can any help me or any ideas would be appreciated



C#
protected override void Render(System.Web.UI.HtmlTextWriter writer)
       {

               foreach (GridViewRow row in gdvauthors.Rows)
               {
                   if (row.RowType == DataControlRowType.DataRow)
                   {
                       row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
                       row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
                       // Set the last parameter to True
                       // to register for event validation.
                       row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(gdvauthors, "Select$" + row.DataItemIndex, true);
                   }
               }
               base.Render(writer);


       }
Posted

1 solution

You just need to do a bit of refactoring, then you can use the same code to render different GridViews

C#
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
       this.RenderGridView(gdvauthors);
       this.RenderGridView(otherGridView);         
       base.Render(writer);
}

private void RenderGridView(GridView gridView)
{
 foreach (GridViewRow row in gridView.Rows)
       {
           if (row.RowType == DataControlRowType.DataRow)
           {
               row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
               row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
               // Set the last parameter to True
               // to register for event validation.
               row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(gdvauthors, "Select$" + row.DataItemIndex, true);
           }
       }
}
 
Share this answer
 
Comments
mrDivan 7-Nov-12 4:50am    
Thank you so much I appreciate it tremendously it worked first time.
jim lahey 7-Nov-12 4:52am    
Glad to be of help
mrDivan 7-Nov-12 5:22am    
Sorry jim just a question should I change the gridview in the foreach loop depending on which gridview i want to be able to select
jim lahey 7-Nov-12 5:26am    
No. You just pass the correct GridView to the RenderGridView(GridView gridView) method.
mrDivan 7-Nov-12 5:37am    
ok thank you will give it a try

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