Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 29, 2007 12:09 AM by mhowell_hrx
Member
125 Points
25 Posts
Mar 20, 2006 06:18 PM|LINK
Hi,
I want to add columns to a gridview control depending on the items in a config datatable in a for / next loop.
Can someone suggest the best way to do this? So far I have:
Dim row as dataset.itemsrow
Dim
Column.DataField =
GridView.Columns.Add(Column )
Next
Is this the correct or will this cause an error?
Contributor
2898 Points
608 Posts
Mar 20, 2006 06:43 PM|LINK
Looks good to me, I code in C# and my code looks like
BoundColumn nameColumn;
foreach(..... )
{
nameColumn = new BoundColumn();
nameColumn.HeaderText = "row col name";
nameColumn.DataField = "row col field";
myDataGrid.Columns.Add(nameColumn);
}
which looks like what you got in vb.net there, so go for it.... if you get an error, let me know, and we will help you through it.
Mar 20, 2006 06:44 PM|LINK
Also, have a look at this article I found, sampling how to create columns of different forms, such as template columns.
http://www.gridviewguy.com/ArticleDetails.aspx?articleID=29
Mar 21, 2006 06:37 AM|LINK
Great, thanks. Will let you know how I get on
Mark
Mar 22, 2006 03:04 PM|LINK
2 Points
1 Post
Jul 29, 2007 12:09 AM|LINK
Just wanted to follow up, with something that took me some time to figure out:
For the DataGrid object, use the BoundColumn object and add it to the Columns collection
For the GridView object, use the BoundField object and add it to the Columns collection
Matthew
mgshortt
Member
125 Points
25 Posts
Adding colums programatically to gridview
Mar 20, 2006 06:18 PM|LINK
Hi,
I want to add columns to a gridview control depending on the items in a config datatable in a for / next loop.
Can someone suggest the best way to do this? So far I have:
Dim row as dataset.itemsrow
Dim
item as String = row.Item("ItemDesc") For Each row In dataset.items Dim Column As System.Web.UI.WebControls.BoundFieldColumn.DataField =
itemGridView.Columns.Add(Column )
Next
Is this the correct or will this cause an error?
jminond
Contributor
2898 Points
608 Posts
Re: Adding colums programatically to gridview
Mar 20, 2006 06:43 PM|LINK
Looks good to me, I code in C# and my code looks like
BoundColumn nameColumn;
foreach(..... )
{
nameColumn = new BoundColumn();
nameColumn.HeaderText = "row col name";
nameColumn.DataField = "row col field";
myDataGrid.Columns.Add(nameColumn);
}
which looks like what you got in vb.net there, so go for it.... if you get an error, let me know, and we will help you through it.
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
jminond
Contributor
2898 Points
608 Posts
Re: Adding colums programatically to gridview
Mar 20, 2006 06:44 PM|LINK
Also, have a look at this article I found, sampling how to create columns of different forms, such as template columns.
http://www.gridviewguy.com/ArticleDetails.aspx?articleID=29
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
mgshortt
Member
125 Points
25 Posts
Re: Adding colums programatically to gridview
Mar 21, 2006 06:37 AM|LINK
Great, thanks. Will let you know how I get on
Mark
mgshortt
Member
125 Points
25 Posts
Re: Adding colums programatically to gridview
Mar 22, 2006 03:04 PM|LINK
mhowell_hrx
Member
2 Points
1 Post
Re: Adding colums programatically to gridview
Jul 29, 2007 12:09 AM|LINK
Just wanted to follow up, with something that took me some time to figure out:
For the DataGrid object, use the BoundColumn object and add it to the Columns collection
For the GridView object, use the BoundField object and add it to the Columns collection
Matthew