Column count / Access GridView Column after DataBind

  • Thread starter Finn Stampe Mikkelsen
  • Start date
F

Finn Stampe Mikkelsen

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

<asp:GridView ID="UdlaanGrd" runat="server" CellPadding="4"
ForeColor="#333333"
GridLines="None" onrowcommand="UdlaanGrd_RowCommand" >

<Columns>
<asp:ButtonField ButtonType="Button"
HeaderText="Fjern Vare" Text="Fjern"
CommandName="Fjern" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:ButtonField>
</Columns>
<AlternatingRowStyle BackColor="White" />

<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>

--
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
don't.
Es gibt 10 Arten von Menschen. Die, die Binär verstehen, bzw. die, die es
nicht tuhen.
 
R

Rajeev Gopal

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
 
F

Finn Stampe Mikkelsen

Subject: Re: Column count / Access GridView Column after DataBind
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.

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 can't
access the whole columns by index...

/Finn
 
R

Rajeev Gopal

Can you try this:

sampleGridView.Rows(0).Cells.Count?

You could place this in Prerender to get the count.
 
F

Finn Stampe Mikkelsen

Rajeev Gopal said:
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's 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 don't 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 don't see the reason for this and think there must be some
hack to do it...

/Finn
 

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,818
Messages
2,569,727
Members
45,661
Latest member
NadineBour

Latest Threads

Top