Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Column count / Access GridView Column after DataBind

Reply
Thread Tools

Column count / Access GridView Column after DataBind

 
 
Finn Stampe Mikkelsen
Guest
Posts: n/a
 
      08-19-2010
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.

 
Reply With Quote
 
 
 
 
Rajeev Gopal
Guest
Posts: n/a
 
      08-20-2010
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
 
Reply With Quote
 
 
 
 
Finn Stampe Mikkelsen
Guest
Posts: n/a
 
      08-20-2010
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
>
> Thanks,
> Rajeev
> http://rajeevgopal.blogspot.com


 
Reply With Quote
 
Rajeev Gopal
Guest
Posts: n/a
 
      08-20-2010
Can you try this:

sampleGridView.Rows(0).Cells.Count?

You could place this in Prerender to get the count.
 
Reply With Quote
 
Finn Stampe Mikkelsen
Guest
Posts: n/a
 
      08-20-2010
"Rajeev Gopal" <(E-Mail Removed)> skrev i meddelelsen
news:(E-Mail Removed)...
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview returns old value of gridview.rows.count! MC ASP .Net 2 12-12-2008 11:15 PM
gridview column values to another page via gridview hyperlink column Keith G Hicks ASP .Net 3 02-18-2008 06:17 AM
databind dataset to gridview in gridview mharness ASP .Net 2 06-29-2007 11:38 AM
Guid column missing after databind to objectlist herman ASP .Net Mobile 0 03-10-2005 03:54 PM
BUG in DataBind? After .DataBind there are more DataGrid Items than DataSet Rows! Michael ASP .Net Datagrid Control 0 12-29-2003 07:47 PM



Advertisments