• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

ASP.NET Grid View - Want to create columns on the fly.

Take a look at the following standard grid view.
<asp:gridview id="CustomersGridView" datasourceid="CustomersSource" autogeneratecolumns="true" emptydatatext="No data available." runat="server">
  <columns>
    <asp:boundfield datafield="CustomerID" headertext="Customer ID"/>
    <asp:boundfield datafield="CompanyName" headertext="Company Name"/>
    <asp:boundfield datafield="Address" headertext="Address"/>
    <asp:boundfield datafield="City" headertext="City"/>
    <asp:boundfield datafield="PostalCode" headertext="Postal Code"/>
    <asp:boundfield datafield="Country" headertext="Country"/>
  </columns>
</asp:gridview>

Open in new window

How can I add the columns using VB or C#?  
0
jdana
Asked:
jdana
2 Solutions
 
Carl TawnSystems and Integration DeveloperCommented:
As an example, based on your first grid column, you could use something like:
            BoundField bc = new BoundField();
            bc.DataField = "CustomerID";
            bc.HeaderText = "Customer ID";
            CustomersGridView.Columns.Add(bc);

Open in new window

Then you just need to repeat for your other columns.
0
 
jdanaAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now