Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing data grid column

Reply
Thread Tools

Accessing data grid column

 
 
John
Guest
Posts: n/a
 
      08-27-2006
Hi

I have a hidden (visible=false) column on a gridview bound to a sql server
table. I am trying to access the field as;

For Each row As GridViewRow In grdEvents.Rows
If row.RowType = DataControlRowType.DataRow Then
bf = CType(row.Cells(row.Cells.Count - 1).FindControl("event id"),
BoundField)
End if
Next

but I get the 'System.Web.UI.Control' cannot be converted to
System.Web.UI.WebControls.BoundField' error. When I try to access it using
row.Cells(12).Text then it returns a blank value.

How can I access the relevant gridview column?

Thanks

Regards


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      08-27-2006
"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I have a hidden (visible=false) column on a gridview bound to a sql server
> table. I am trying to access the field as;
>
> For Each row As GridViewRow In grdEvents.Rows
> If row.RowType = DataControlRowType.DataRow Then
> bf = CType(row.Cells(row.Cells.Count - 1).FindControl("event id"),
> BoundField)
> End if
> Next
>
> but I get the 'System.Web.UI.Control' cannot be converted to
> System.Web.UI.WebControls.BoundField' error.


Hmm - not precisely certain what you're trying to do here... Clearly, you
don't actually need to convert a column into a BoundField or anything else
just to interrogate its contents...

> When I try to access it using row.Cells(12).Text then it returns a blank
> value.


Sounds like you've discovered one of the new features of GridViews, whereby
hidden columns are not saved in ViewState by default...

> How can I access the relevant gridview column?


Set the column Visible = True immediately before calling the GridView's
DataBind method, then set it Visible = False immediately afterwards...


 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      08-27-2006
Hi

I have used the 'Configure Data Source' to bind the gridview. Where would I
find the databind method in this case?

Thanks

Regards

"Mark Rae" <(E-Mail Removed)> wrote in message
news:e$(E-Mail Removed)...
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>
>> How can I access the relevant gridview column?

>
> Set the column Visible = True immediately before calling the GridView's
> DataBind method, then set it Visible = False immediately afterwards...
>



 
Reply With Quote
 
KJ
Guest
Posts: n/a
 
      08-28-2006
Hello John,

I am guessing you used an ObjectDataSource control to act as a
datasource for the gridview? Check the following:

The DataSourceID property of the gridview is set to that of the
objectdatasource.
WHen you call DataBind() on the gridview, the SelectMethod of the
objectdatasource is implicitly called.

John wrote:
> Hi
>
> I have used the 'Configure Data Source' to bind the gridview. Where would I
> find the databind method in this case?
>
> Thanks
>
> Regards
>
> "Mark Rae" <(E-Mail Removed)> wrote in message
> news:e$(E-Mail Removed)...
> > "John" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >
> >
> >> How can I access the relevant gridview column?

> >
> > Set the column Visible = True immediately before calling the GridView's
> > DataBind method, then set it Visible = False immediately afterwards...
> >


 
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
Accessing data grid column John ASP .Net Datagrid Control 2 08-28-2006 05:16 AM
Data Grid Column Visibility in vb.net Balu ASP .Net 4 01-12-2006 06:02 PM
Data Grid Column Visibility Balu ASP .Net 0 01-03-2006 05:54 AM
Activa or not activate a button column depending if another data column has data or not carlos perez ASP .Net 0 06-08-2004 02:16 PM
How do you alternate images in a data bound column of a data grid control? C Newby ASP .Net 7 04-02-2004 05:00 PM



Advertisments