manipulating datagrid at runtime

K

KK

Hi

I use datagrid webcontrol on my webform. Curently I execute
stored procedures, fill a dataset, then set the datasource property
of the datagrid to show the data. What I want to know is;

I want to hide/remove certain columns after binding.
but if i use datagrid.columns[0].visible=false it doesn't work
anyway it shows 0 for column count. Because I want to hide
the tables primary key column.

So basicaly, how can I programaticaly add/remove/hide columns
and bind my dataset? .Net help regarding this binding wasn't very
helpfull.

I do not want to add columns and bind them at design time.
Everything, should be able to setup at run time and assign the
dataset.

thanks
KK
 
A

Alvin Bruney

autogenerated columns aren't added to the column collection at runtime which
is why the count is returning zero. You will need to remove these columns in
either the itemcreated or itemdatabound event handlers. The column layout
will follow the order of your query select clause.

Consider select A, B, C from [snip]
Creates an autogenerated column where index 0, 1, 2 map directly to A, B, C.
To remove column C you would need the following code:
e.Item.Cells[2].Visible = false;
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top