PC Review


Reply
Thread Tools Rate Thread

Accessing data grid column

 
 
John
Guest
Posts: n/a
 
      27th Aug 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
 
      27th Aug 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
 
      27th Aug 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
 
      28th Aug 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
Rate This Thread
Rate This Thread:

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 based on grid selected row =?Utf-8?B?Um9iIE1vcnJpc3M=?= Microsoft Dot NET Compact Framework 4 14th Nov 2006 03:27 PM
Data grid column =?Utf-8?B?YXNhZA==?= Microsoft ASP .NET 3 27th Apr 2005 04:02 AM
Show Serial Number Column Along with Data in data grid =?Utf-8?B?QWRuYW4=?= Microsoft Dot NET Compact Framework 0 31st Jan 2005 09:49 AM
custom data column headers, specific columns with web data grid =?Utf-8?B?YW5kcmV3Y3c=?= Microsoft C# .NET 0 9th Jul 2004 05:32 AM
How do you alternate images in a data bound column of a data grid control? C Newby Microsoft ASP .NET 7 2nd Apr 2004 06:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:17 PM.