SqlDataSource.Select
(1)
SqlDataSource
(1)
GridView
(1)
DataBindHiYeah
(1)
DataBind
(1)
Button
(1)
AutoGenerateof
(1)
Cells.Count
(1)

Column count / Access GridView Column after DataBind

Asked By Finn Stampe Mikkelsen
19-Aug-10 08:44 AM
Hi

I have below GridView, which i in codebehind page databind with a dynamicly
created datatable.

This all works fine, but after the databind i still only have a column count
of 1 although the datatable adds another 4 columns to the gridview. This
represents a problem, since i would like to have the last column properties
change on the fly and i cannot access the properties of any column besides
the on definded below. None of the databound columns created by the DataBind
method can be accessed..

How can i access these columns??

/Finn

ForeColor="#333333"
GridLines="None" onrowcommand="UdlaanGrd_RowCommand" >

HeaderText="Fjern Vare" Text="Fjern"
CommandName="Fjern" >

ForeColor="White" />
ForeColor="White" />
HorizontalAlign="Center" />
ForeColor="#333333" />

--
Der er 10 slags mennesker - Dem som forst?r bin?r og dem som ikke g?r.
There are 10 kinds of people. Those who understand binary and those who
do not.
Es gibt 10 Arten von Menschen. Die, die Bin?r verstehen,  bzw. die, die es
nicht tuhen.

Finn,If you mention the columns in the GridView (not allowing AutoGenerateof

Rajeev Gopal replied to Finn Stampe Mikkelsen
20-Aug-10 07:48 AM
Finn,
If you mention the columns in the GridView (not allowing AutoGenerate
of Columns), then you can get access to the column count. As of now
the grid is aware of only one column and that is of Button.

Hope you got it.

Thanks,
Rajeev
http://rajeevgopal.blogspot.com

Subject: Column count / Access GridView Column after DataBindHiYeah, well

Finn Stampe Mikkelsen replied to Rajeev Gopal
20-Aug-10 12:23 PM
Subject: Re: Column count / Access GridView Column after DataBind


Hi

Yeah, well then it is not dynamic and i need to autogenerate the individual
columns..

Funny enough, the individual rows have knowledge of the correct number of
cells, including the one i want to make invisible.. I find it curious, that
i can make individual cells invisible and access them by index, but i cannot
access the whole columns by index...

/Finn

Can you try this:sampleGridView.Rows(0).Cells.Count?

Rajeev Gopal replied to Finn Stampe Mikkelsen
20-Aug-10 02:26 PM
Can you try this:

sampleGridView.Rows(0).Cells.Count?

You could place this in Prerender to get the count.
I know the count of cells and it is correct and as expected in regard to
Finn Stampe Mikkelsen replied to Rajeev Gopal
20-Aug-10 03:25 PM
I know the count of cells and it is correct and as expected in regard to the
SqlDataSource.Select command... What i need is a way to dynamicly determin
if i wan't to show a specific column of the data bound from the
SqlDataSource.

If for some reason i dont want to see the 3rd column, i want to do a
.visible = false; to the property of that column. I cannot do that, but i
can do it the individuel rows 3rd cell (Cells[3]). This leaves the header
row visible and indicates to the user that data is invisible.

Whar i do not understand is, why the databound gridview, after the dataBind,
cannot return a correct column.count but the individual rows of the same
gridview can... I do not see the reason for this and think there must be some
hack to do it...

/Finn
Post Question To EggHeadCafe