GridView "visible=False" data items not accessible? programattically

O

ohyeahgo

this might be an easy one.

So "everything" is working and this GridView and it is NOT used to
update data.

I'm attempting to get to the "invisible" data columns in a gridview. I
can easily access the shown data by

doing something like this, it works for "visible" data but no hidden
columns in my gridview.

For Each Row In GridView1.Rows
For J = 0 To 57
testhold = Row.Cells.Item(J).Text.ToString
Next
Next


Watch shows.

J = 0, Testhold = '' <- this is whats wrong, there
should be data here.
J = 1, Testhold = '3.0'
etc

Basically any "visible" items data will show in the above loop. No
"Visible = False" columns retain underneath data. (im trying to use
keys without showing them to the user).

Asp code ex... Supname always shows up empty (''). MonOtHrs shows
the correct data.

<asp:BoundField DataField="SupName" HeaderText="SupName"
SortExpression="SupName" Visible="False" />

<asp:BoundField DataField="MonOtHrs" HeaderText="OT"
SortExpression="MonOtHrs"
</asp:BoundField>
 
O

ohyeahgo

this works...

Dim key As DataKey = GridView1.DataKeys(0)


For J = 0 To 57
testhold = key.Item(2).ToString (key field
num 2)
testhold = Row.Cells.Item(J).Text.ToString

Next
 
W

Wouter van Vugt

Hi,

I think a invisible column isn't rendered on the clientside, and hence
no roundtrip for that data. So basically, yes you have to use
datakeynames and the datakeys collection to make this work.

Grtz, Wouter van Vugt
 
E

Edo den Haring

If datakeys can't be used ?

Is it possible to get to the datarow via
Dim row DataRowView = CType(GridViewRow.DataItem (selectedrow))beneath t
row("FieldName") ?

I tried this but dataitem is Nothing ...

In DataRowBound event is it possible to get to all the datafields in the
dataset via the dataitem.
 
T

Teemu Keiski

Hi,

data source items & fields aren't stored with the GridView to ViewState
(DataKeys being clear exception), so DataItem property is actually only
accessible during the same sequence after the GridView has been bound (in
practise in RowCreated and RowDataBound events raised after call to
DataBind).
 
E

Edo den Haring

Hi,

Thanx ...

I was afraid for this ... :)

I tried to get the current record data into my own object after selection
(using the select button) via the databoundrecord event.

Using row.rowtype = datarow and row.rowstate = select I tried to isolate the
record be selected. It did not work ... I seems that not each select click
(using the select button) the datarowbound event is fired ...

Is this correct ?

Greetz,

Edo
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top