B
botham782
Hi,
I cannot grab the text of a datagrid row's cell. I am trying to access
the value in the datagrid's ItemCreated event. I use a conditional
statement in the ItemCreated event to ensure that I'm "looking at" an
Item or AlternatingItem. I have checked out numerous posts related to
this, but for some reason just cannot get anything useful other than an
empty string. Sorry in advance for asking a fairly popular question.
I want to get the text of the row's cell(0), which is the first column
that I defined in my datagrid. I will ultimately use this later in the
code of this same event when I add an attribute to the entire row. The
attribute will be a javascript onclick event which allows the entire
row to be clicked, taking the user to a "detail" page relating to the
information in that datagrid row. The value of that cell(0) will be
concatenated to the querystring referenced by the onclick event.
At first I had the column defined as a TemplateColumn. I had a
HyperLink control inside the column which I used temporarily as a way
for the user to get to the detail page. I tried to reference that cell
by using:
Dim CellControl As HyperLink =
CType(e.Item.Cells(0).FindControl("hlStockNumber"), HyperLink)
Dim TestStockNumber As String = CellControl.NavigateUrl
'--> debugger says TestStockNumber's value is: ""
Then I tried to change the column to a BoundColumn. I tried to
reference that column by using:
Dim TestStockNumber As String = e.Item.Cells(0).Text
'--> debugger says TestStockNumber's value is: ""
Next I changed the column back to a TemplateColumn. I changed the
control that the data was stored in in the cell to a label and tried to
reference it like this:
Dim TestStockNumber As String =
CType(e.Item.Cells(0).FindControl("lblStockNumber"), Label).Text
'--> debugger says TestStockNumber's value is: ""
I finally tried a method similar to the above, but taking the data out
of a control entirely:
Dim TestStockNumber As String = CType(e.Item.Cells(0).Controls(0),
DataBoundLiteralControl).Text
'--> debugger says TestStockNumber's value is: ""
What in the world am I doing wrong? Any help would be greatly
appreciated.
Thanks
I cannot grab the text of a datagrid row's cell. I am trying to access
the value in the datagrid's ItemCreated event. I use a conditional
statement in the ItemCreated event to ensure that I'm "looking at" an
Item or AlternatingItem. I have checked out numerous posts related to
this, but for some reason just cannot get anything useful other than an
empty string. Sorry in advance for asking a fairly popular question.
I want to get the text of the row's cell(0), which is the first column
that I defined in my datagrid. I will ultimately use this later in the
code of this same event when I add an attribute to the entire row. The
attribute will be a javascript onclick event which allows the entire
row to be clicked, taking the user to a "detail" page relating to the
information in that datagrid row. The value of that cell(0) will be
concatenated to the querystring referenced by the onclick event.
At first I had the column defined as a TemplateColumn. I had a
HyperLink control inside the column which I used temporarily as a way
for the user to get to the detail page. I tried to reference that cell
by using:
Dim CellControl As HyperLink =
CType(e.Item.Cells(0).FindControl("hlStockNumber"), HyperLink)
Dim TestStockNumber As String = CellControl.NavigateUrl
'--> debugger says TestStockNumber's value is: ""
Then I tried to change the column to a BoundColumn. I tried to
reference that column by using:
Dim TestStockNumber As String = e.Item.Cells(0).Text
'--> debugger says TestStockNumber's value is: ""
Next I changed the column back to a TemplateColumn. I changed the
control that the data was stored in in the cell to a label and tried to
reference it like this:
Dim TestStockNumber As String =
CType(e.Item.Cells(0).FindControl("lblStockNumber"), Label).Text
'--> debugger says TestStockNumber's value is: ""
I finally tried a method similar to the above, but taking the data out
of a control entirely:
Dim TestStockNumber As String = CType(e.Item.Cells(0).Controls(0),
DataBoundLiteralControl).Text
'--> debugger says TestStockNumber's value is: ""
What in the world am I doing wrong? Any help would be greatly
appreciated.
Thanks