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

  • Home
  • SEARCH
  • 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 652001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:13:24+00:00 2026-05-13T22:13:24+00:00

How do I dynamically create a DataGridView in C#? Could you please provide an

  • 0

How do I dynamically create a DataGridView in C#? Could you please provide an example?

  • 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-05-13T22:13:25+00:00Added an answer on May 13, 2026 at 10:13 pm

    You can create it like any other controls.

    place a PLACEHOLDER control in your page (this will serve as start point)

    so your page looks like

    <body>
        <form id="form" runat="server" />
        <asp:PlaceHolder id="ph" runat="server" />
    </body>
    

    Then, in your code behind, just create and add controls to the Place Holder

    // Let's create our Object That contains the data to show in our Grid first
    string[] myData = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
    
    // Create the Object
    GridView gv = new GridView();
    
    // Assign some properties
    gv.ID = "myGridID";
    gv.AutoGenerateColumns = true;
    
    // Assing Data (this can be a DataTable or you can create each column through Columns Colecction)
    gv.DataSource = myData;
    gv.DataBind();
    
    // Now that we have our Grid all set up, let's add it to our Place Holder Control
    ph.Controls.Add(gv);
    

    Maybe you want to add more controls?

    // How about adding a Label as well?
    Label lbl = new Label;
    lbl.ID = "MyLabelID";
    lbl.Text = String.Format("Grid contains {0} row(s).", myData.Length);
    
    ph.Controls.Add(lbl);
    
    // Done!
    

    Hope it helps get you started

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to dynamically create syntax rules inside a function. For example, something like:
If I dynamically create an element through the click of a button, for example,
I have a dynamically created DataGridView that has a valid DataSource with one row
Am attempting to dynamically create html which then injects itself as an iframe into
I want to dynamically create instance method of child class through class method of
I'm trying to dynamically create a navbar from data i fetch from a web
Is it possible to dynamically create a select statement with multiple where() clauses? Suppose
I'm trying to dynamically create alert messages using the jQuery plugin for Bootstrap CSS.
I'm trying to dynamically create a link from a Windows Form to our website
I am trying to dynamically create an XML file using php like this: header

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.