DataGrid - how to configure columns in C# code?

D

Dmitry Bond.

Hello All.

Could you please help me with DataGrid?
The situation is the following:
I have a DataSet with some data to display in DataGrid.
In the configuration file I have a (comma-separated) list of columns of that
DataSet to display.
The first column in DataGrid should contains checkbox, rest of columns
should be configured at run-time.
How can I do this?

Just to give you an idea I provide a piece of code:

private void gridReports_DataBinding(object sender, System.EventArgs e)
{
this.reportsView = new
DataView(this.reportsTabs.Tables[this.selectedTableIndex]);
this.reportsView.Sort = "title";
gridReports.DataSource = this.reportsView;

// get list of columns to display
ArrayList colList =
(this.ReportsEngineObj.GetMetadataItem("ReportsListColumns") as ArrayList);
// if not available - init default
if (colList == null)
{
colList = new ArrayList();
colList.Add("title");
}
foreach (string colName in colList)
{
TemplateColumn gc = new TemplateColumn();
gc.HeaderText = "<b>" + colName + "</b>";
gc.ItemTemplate = ???!!! <<=== here I have problems! I just do not
know what should be here...
gridReports.Columns.Add(gc);
}
}

I browse MSDN but samples I found have predefined set of columns defined in
ASPX file.
But I need to configure columns in C# code...
How can I do this?


WBR, Dmitry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top