By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,263 Members | 1,642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,263 IT Pros & Developers. It's quick & easy.

datagrid column exists

P: n/a
Hi,

I am creating datagrid bound column dynamically and need to check if a
datagrid column already exists?Is there a way to check this?

thanks
gane
Jun 5 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Is datagrid's Columns collection good for you? Note, that autogenerated
columns don't get there.

Eliyahu

"gane" <ga**@sdff.com> wrote in message
news:Ow**************@TK2MSFTNGP05.phx.gbl...
Hi,

I am creating datagrid bound column dynamically and need to check if a
datagrid column already exists?Is there a way to check this?

thanks
gane

Jun 6 '06 #2

P: n/a
Hi,

Can you show me with a sample code?
I have something like this, i need to check if the column exists before i
add to the grid. how can i do with the collections.
foreach(DataColumn c in dsinfo.Tables[0].Columns)

{

dgresults.Columns.Add(CreateBoundColumn(c));

}

Thanks

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e6*************@TK2MSFTNGP02.phx.gbl...
Is datagrid's Columns collection good for you? Note, that autogenerated
columns don't get there.

Eliyahu

"gane" <ga**@sdff.com> wrote in message
news:Ow**************@TK2MSFTNGP05.phx.gbl...
Hi,

I am creating datagrid bound column dynamically and need to check if a
datagrid column already exists?Is there a way to check this?

thanks
gane


Jun 6 '06 #3

P: n/a
gane wrote:
Hi,

I am creating datagrid bound column dynamically and need to check if a
datagrid column already exists?Is there a way to check this?

Dynamically created columns do not persist between page loads so I'm not
sure why you need to check.You should only dynamically create and add
columns to a datagrid in the Page_Init event. From online help:

The DataGrid control does not store the contents of its Columns
collection into the view state. To add or remove a column dynamically,
you must programmatically add or remove the column everytime the page is
refreshed. Provide a Page_Init function that adds or removes the column
before the DataGrid control's state is reload and the control is
rebuilt. Otherwise, the changes to the Columns collection are not
reflected in the DataGrid control when it is displayed.
Note Although you can programmatically add columns to or remove
columns from the Columns collection of the DataGrid control, it is
easier to list the columns statically and then use the Visible property
to display or hide each column.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 6 '06 #4

P: n/a
I am using sort functionality on the datagrid, which is not firing if i dont
have the datagrid binded in pageload.
so i need to rebind twice in pageload and onsortcommand, which creates the
dynamic bound columns twice.
But now i clearing the grid, instead of finding a way to check for existing
columns. Now it works.

Thanks
Gane
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uQ**************@TK2MSFTNGP04.phx.gbl...
gane wrote:
Hi,

I am creating datagrid bound column dynamically and need to check if a
datagrid column already exists?Is there a way to check this?

Dynamically created columns do not persist between page loads so I'm not
sure why you need to check.You should only dynamically create and add
columns to a datagrid in the Page_Init event. From online help:

The DataGrid control does not store the contents of its Columns
collection into the view state. To add or remove a column dynamically,
you must programmatically add or remove the column everytime the page is
refreshed. Provide a Page_Init function that adds or removes the column
before the DataGrid control's state is reload and the control is
rebuilt. Otherwise, the changes to the Columns collection are not
reflected in the DataGrid control when it is displayed.
Note Although you can programmatically add columns to or remove
columns from the Columns collection of the DataGrid control, it is
easier to list the columns statically and then use the Visible property
to display or hide each column.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jun 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.