Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:48:11+00:00 2026-06-12T10:48:11+00:00

I have about 11 GridViews on my page: GridView1, GridView2, … GridView10 and GridViewActive.

  • 0

I have about 11 GridViews on my page: GridView1, GridView2, … GridView10 and GridViewActive.
GridView1 to GridView10 are invisible, but GridViewActive is Visible.
Based on different conditions I need to copy structure of one GridView to GridViewActive.
I need to do something like

//common params
SqlDataSource1.SelectParameters["CommonParam1"].DefaultValue = this.commonParam1;      
if (reportname = "report1") 
{
    SqlDataSource1.SelectParameters["Param"].DefaultValue = this.param;      
    CopyGridViewStructure(GridView1, GridViewActive); 
}
else if (reportname = "report2") 
{ 
    SqlDataSource1.SelectParameters["AnotherParam"].DefaultValue = this.anotherParam;
    CopyGridViewStructure(GridView2, GridViewActive); 
}
etc.

// DO OTHER STAFF WITH GRIDVIEWATIVE HERE AND IN OTHER METHODS

And on button click (actually it is a bit more complicated than simple ButtonClick, as it is Ajax which calls Button click, and button is actually invisible for user):

//this block doesn't work for now, because grvActive doesn't have any structure
this.grvActive.DataSource = SqlDataSource1; 
this.grvActive.DataBind();

I need to copy only Columns. Have not found sollution for this. GridView doesn’t contain Clone method.

EDIT:

GridView1 to GridView10 and GridViewActive are not dynamically created.
Example of GridView:

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" Visible="false">
            <Columns>
                <asp:BoundField DataField="username" HeaderText="First Name">
                    <ItemStyle Width="110px"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="usersurname" HeaderText="Last Name">
                    <ItemStyle Width="110"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="usertype" HeaderText="User Type">
                    <ItemStyle Width="100px"></ItemStyle>
                </asp:BoundField>
                <asp:TemplateField HeaderText="Login">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblLastModifyDate" Text='<%# MyUtility.MyCommon.FormatDate(Eval("logindate").ToString()) %>' />
                    </ItemTemplate>
                    <ItemStyle Width="177px"></ItemStyle>
                </asp:TemplateField>
                </Columns>
        </asp:GridView>

Other GridView are very similar, but with different columnnames and datafields. Some of them contains different TemplateField, some doesn’t have TemplateFields at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:48:12+00:00Added an answer on June 12, 2026 at 10:48 am

    I have not found a sollution for copying GridView structure, however, I have found a solution for my problem. Instead of Cloning structure, I am saving GridView ID and then I am using FindControl.

    private string GridID 
    {
            get
            {
                return ViewState["GridID "].ToString();
            }
            set
            {
                ViewState["GridID "] = value;
            }
    }
    

    And then

    SqlDataSource1.SelectParameters["CommonParam1"].DefaultValue = this.commonParam1;       
    if (reportname = "report1")  
    { 
        SqlDataSource1.SelectParameters["Param"].DefaultValue = this.param;       
        // //CopyGridViewStructure(GridView1, GridViewActive);  
        GridID = "GridView1";
    } 
    else if (reportname = "report2")  
    {  
        SqlDataSource1.SelectParameters["AnotherParam"].DefaultValue = this.anotherParam; 
        CopyGridViewStructure(GridView2, GridViewActive);  
        GridID = "GridView2";
    } 
    etc.
    

    And when I need to use gridView, I am using FindControl:

    GridView grd = (GridView) this.FindControl(GridID);
    
    // actually for my page I am using masterpage and FindControl is a bit more complicated:
    GridView grd = (GridView)((ContentPlaceHolder)(this.Controls[0].FindControl("mainContent"))).FindControl(GridID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have gridview1 on sample.asp page. It has about 15 rows. What i want
I have an ASP.NET 4.0 home page which displays about 20 product listings. Each
So, this question may be a little vague, but I have constant discussions about
I have a reasonably simple page setup with four accordian panes and four gridviews
I have a page with .Net grid view with about 12 text fields per
Question about GridView sorting in VB.NET: I have a GridView with AutoGenerateColumns = True
I have to set GridView.DataKeyNames (This is really a question about the syntax for
I have about 50 arrays filled with numbers and I have to report out
I have about 20 grid views that I have to create. All of them
i have about 60 fragments ListFragment , now i use each Listfragment with another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.