Binding Columns in DatagridView C#
My problem is in my webpage i have a datagridview and i would like to populate it with data from my sql Db. my way was to link the Datagridview with a table from my Dataset, also as long as i have Data fields linking to the correct columns from table mentioned in my markup page( ). it all works.
i did not like the way how i bounded the columns to the datagridview columns.
could somebody please suggest a better way? using pure c# code only and not have to do anything with the markup page.
Thanks for your time
Adrian

Roei BarRank #1,271 · 1.4K reputationPosted Aug 11, 2009, 9:33 PM EDT
you will get back a dataset
and no the dataset you can do the following
you can use DAAB here is the download link :
http://geekswithblogs.net/mnf/archive/2007/03/19/109142.aspx
adrian Wonder5 reputationPosted Aug 11, 2009, 9:47 PM EDT
Master BillaRank #2,229 · 630 reputationPosted Aug 12, 2009, 12:32 AM EDT
You add gridview in htm page.
Then add code like this way
protected void Button1_Click(object sender, EventArgs e) { GridView1.AutoGenerateColumns = false; BoundField minPurchase = new BoundField(); minPurchase.HeaderText = "Minimum Purchase"; minPurchase.DataField = "MINIMUM"; GridView1.Columns.Add(minPurchase); BoundField pricePer = new BoundField(); pricePer.HeaderText = "Price Per Item"; pricePer.DataField = "PRICE_PER"; pricePer.DataFormatString = "${0}"; GridView1.Columns.Add(pricePer); }Then you can bind data to gridview.
thank you
adrian Wonder5 reputationPosted Aug 12, 2009, 3:09 PM EDT
Master BillaRank #2,229 · 630 reputationPosted Aug 12, 2009, 6:39 PM EDT
When you are allow to gridview AutoGenerateColumns is true, then it will handle the all columns(you don't give the data fields name to every columns).
Just give make it your gridview is AutoGenerateColumn is true then take look.
Thank you