Click here to Skip to main content
Rate this: bad
good
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 4:10am

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 at 7-Nov-12 4:50am
   
Thank you so much I appreciate it tremendously it worked first time.
jim lahey at 7-Nov-12 4:52am
   
Glad to be of help
mrDivan at 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 at 7-Nov-12 5:26am
   
No. You just pass the correct GridView to the RenderGridView(GridView gridView) method.
mrDivan at 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
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 Shweta N Mishra 244
3 BillWoodruff 235
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2014
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