Click here to Skip to main content
12,292,562 members (67,098 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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



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 6-Nov-12 3:10am
mrDivan1.2K

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160518.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100