I have a data set with about 15 columns, and I also have an ASP.net gridview. I was wondering if any one knew how I can populate the gridview with the dataset, but the issue is I just want a few of the columns from the dataset.
at the moment I'm just doing
GridView1.DataSource = ds;
GridView1.DataBind();
but this obviously binds all the columns from the dataset to the gridview.
GridView listTypeBot = new GridView(); // Create my column BoundField bf = new BoundField(); bf. HeaderText = "Types of bot available"; // Add my column to my gridview listTypeBot. Columns. Add(bf); // Create a row and a cell GridViewRow gvr = listTypeBot.
So you are looking to create columns at runtime? Try this:
http://www.codeproject.com/KB/aspnet/dynamic_Columns_in_Grid.aspx
Alternatively, you can configure your gridview ahead of time in the aspx:
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />
<asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
<asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Price" HtmlEncode="False" SortExpression="UnitPrice" />
</Columns>
And make sure you set AutoGenerateColumns to false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With