473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataGrid - how to configure columns in C# code?

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("ReportsLis tColumns") 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.
Nov 19 '05 #1
2 1941
Hi Bond,
You can download some sample code which illustrates the same here
http://www.expertszone.com/samples/checkboxdatagrid.zip
Hope that helps ..
--
The best
srini
http://www.expertszone.com
"Dmitry Bond." wrote:
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("ReportsLis tColumns") 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.

Nov 19 '05 #2
Thank you very much for that sample. :-)
It also answers me the next question - could I use in the DataGrid cell
values from other columns of DataSet.
By writing my HtmlLiteralTemplate I got access to full data row...

"srini" <sr***@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Hi Bond,
You can download some sample code which illustrates the same here
http://www.expertszone.com/samples/checkboxdatagrid.zip
Hope that helps ..
--
The best
srini
http://www.expertszone.com

[...]
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Reb | last post by:
I am using a datagrid within another datagrid. My second datagrid is expand/collapse one. I am facing some error. This is my code. ExpandGrid.aspx <form id="Form1" method="post"...
1
by: VenuGopal | last post by:
Hii!! I have a datagrid which i am using for both dispaly and as well as taking input from the user. Noe there is a particular column which i need to lock, so that the user cannot enter...
1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
7
by: CanoeGuy | last post by:
I have been trying for the last two weeks to display a dynamic DataGrid. The data that I'm pulling from a SQL Server DB will have whole columns that will be either NULL or 0. I want to display...
1
by: Mok | last post by:
Hello, I want to pull information from a table in sql server, bind it to a grid and update those values. I would like to know the best way to do it. I used the configure data adapter wizard and it...
0
by: Stewart | last post by:
Sorry for the cross post. Not sure which forum covers these issues: I'm hoping someone can help me figure out what I'm missing in my code. I am trying to configure a Datagrid for editing. So...
2
by: Cindy | last post by:
Hello. For some reason, I am able to "connect" to the Northwind database whenever I use the wizard; however, when I run the application, my datagrid does not display. Here are the exact steps I...
7
by: Mark B | last post by:
Can someone write some VB.Net example code for me that does this: 1) Creates a gridview control with the results of a SQL stored procedure that has 1 parameter (text) 2) Adds an extra column...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.