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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top