473,398 Members | 2,403 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,398 software developers and data experts.

datagrid column exists

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
4 2891
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: amber | last post by:
Hello, I have a datagrid with about 5 columns. It's datasource is a dataset that also contains a 'comments' field, but I'm not displaying it, as it would take up too much space. What I would like...
1
by: Alpha Zero | last post by:
Hi! I have a datagrid containing single column. If user adds a new word, I want to check if this word does not contain any character except A-Z and this word doesn't exists in previous rows . If...
1
by: Newbie | last post by:
Hello! I need help in making my datagrid sortable by clicking a column header. In the datagrid's property builder, Allow Sorting is checked. I am using a Bound column and it's Sort Expression...
2
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
5
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
2
by: simon | last post by:
I have template column in dataGrid and visible=false. <asp:TemplateColumn visible=false> <ItemTemplate><asp:CheckBox Runat=server ID=chkExists Checked='<%# Container.DataItem( "obstaja" ) % ...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
0
by: Subhash | last post by:
Hello All I have one problem related to Datagrid. I have one datagrid which has a column. The data which is supposed to appear in this column contains mulitple lines. But I want them all to...
2
by: cj | last post by:
I was looking over some of my 2003 code today (see below) that loads a foxpro table via oledb connection. I used a sub "autosizecolumns" I found on the web but I never quite understood why they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.