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 3:10am
mrDivan860

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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 600
1 Tadit Dash 305
2 Sergey Alexandrovich Kryukov 250
3 Peter Leow 190
4 OriginalGriff 148
0 Sergey Alexandrovich Kryukov 9,395
1 OriginalGriff 5,473
2 Peter Leow 4,150
3 Maciej Los 3,540
4 Abhinav S 3,333


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