Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unable to access some grid data

Status
Not open for further replies.

threeo

Programmer
Mar 31, 2005
49
US
anyone know why.....

i have a grid on a page which has 3 colums and looks like this:

EDIT | 25067 | 78655
EDIT | 19876 | 23478
EDIT | 78545 | 87554

when i attempt to access the data from the grid like:

ogrid.Items(0).Cells(1).Text i get "25067"

which is what i would expect.

but for some reason i can NOT access the data in the last column...

ogrid.Items(0).Cells(2).Text i get ""

in fact, all column 3 items come out as ""

ogrid.Items(0).Cells(2).Text i get ""
ogrid.Items(1).Cells(2).Text i get ""
ogrid.Items(2).Cells(2).Text i get ""

anyone know why???

 
You have to do a findcontrol to get the value:
Code:
   oGrid.Items(0).Cells(2).FindControl(control name).Text
 
actually....
i can't seem to get it to work.....

here's how it's set up:

<asp:TemplateColumn HeaderText="Value" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<%# Container.DataItem("AttributeValue") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Columns="20" id="txtAttributeValue" dir=rtl Font-Name="Tahoma" Font-Size="9pt" ForeColor="#006699" runat="server" Text='<%# Container.DataItem("AttributeValue") %>' />
</EditItemTemplate>
</asp:TemplateColumn>

i can't seem to be able to do a findcontrol on the ItemTemplate as it has no ID and when i try to assign it an ID it fails.
 
Code:
oGrid.Items(0).Cells(2).FindControl("txtAttributeValue").Text

doesn't work?
 
when i try that....
i get the error "text" is not a member of "control"

in fact...if you type all the way the final "."
the drop down choices don't include "text"
 
Try:
Code:
 CType(oGrid.Items(0).Cells(2).FindControl("txtAttributeValue"), TextBox).Text()
 
I haven't tested this but:

Code:
Dim Attribute As String = CType(oGrid.Items(0).Cells(2).FindControl("txtAttributeValue"), TextBox).Text
 
?CType(oGrid.Items(0).Cells(2).FindControl("txtAttributeValue"), TextBox).Text()

Referenced object has a value of 'Nothing'.
 
You have to convert it to C#, the examples were in VB.
Code:
some value = ((TextBox)(dgTest.Items(0).Cells(2).FindControl("txtAttributeValue"))).Text();
 
i can't get it to work.

i think the main problem is this:
Referenced object has a value of 'Nothing'.

it just doesn't know what

oGridAttributes.Items(0).Cells(2).FindControl("txtAttributeValue")

is

i don't know why

just can't get the syntax for it
 
for example,

even doing this:

?oGridAttributes.Items(0).Cells(2).FindControl("txtAttributeValue").Parent

yields:
Referenced object 'FindControl' has a value of 'Nothing'.
 
what is oGridAttributtes.. I thought it was oGrid? where are you placing this code?
 
Dim oGridAttributes As DataGrid = CType(oRow.FindControl("dgAttributes"), DataGrid)

oGridAttributes is the name of the grid i'm trying to address....

actually i'm not sure why the above code works but when i do:

?ogridattributes.Items(0).Cells(1).Text

i get the right response:
"UserID"
 
What and where is the code to get the value?
YOu have to create a variable of datagriditem as some point in order to refernce the value.

Please post your original code used to get the values.
 
before i was going to do any coding into the application, i first ran the application and put a break at the point where i was going to need to access the data.

then....i switched to the immediate window to do a pre-development of the code as i was uncertain how to access the data and was going to try and see if i could figure it out. so far....i haven't been able to figure out how to address the last column of data in the datagrid. the column is a template column. it has an id. yet the findcontrol can not locate it.

this works:
?ogridattributes.Items(0).Cells(1).Text

(yields:"UserID")
but trying to access the very next column doesn't work:

?ogridattributes.Items(0).Cells(2).Text

(yeilds:"")

since it is a template column we were trying to figure out a way to use 'FindControl' but it also wasn't working:

?CType(oGridAttributes.Items(0).Cells(2).FindControl("txtAttributeValue"), TextBox).Text()

(yields:Referenced object has a value of 'Nothing')

that's where i stand right now.
 
i believe this is the source of my problem....

my grid is rendered as:

<Columns>
<asp:EditCommandColumn EditText="Edit"
Text="Cancel" UpdateText="Update" />
<asp:BoundColumn DataField="RequiredText"
ReadOnly="True"
HeaderText="Attribute">
</asp:BoundColumn>
<asp:TemplateColumn
HeaderText="Value"
ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<%# Container.DataItem("AttributeValue") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Columns="20"
id="txtAttributeValue"
dir=rtl
Font-Name="Tahoma"
Font-Size="9pt"
ForeColor="#006699"
runat="server"
Text='<%# Container.DataItem("AttributeValue") %>' />
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>

my problem is.....
i am trying to get the value in the column before the user clicks "edit" and the edittemplate takes over.
the regular template has no ID - and i can't figure out how to give it an ID like the edit template has. so....i can't address the cell in the grid.

any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top