Hi,
In ItemCreated data has not been restored from ViewState yet, there is
nothing in the cell when that event runs. Related to your problems, seems as
if those control's Text hasn't been set in the databinding expression or
ItemDataBound correctly? Unless you have tried all that too in ItemCreated,
which would explain.
Anyways, sure way to get to it, is to have code in DataGrid's PreRender
event and then loop through all items in Items collection, search for the
respective data from each item (or controls if that's the need) and set
those properties attributes whatever you are trying to set.
FYI: I've demonstrated creating a row-clickable datagrid
http://blogs.aspadvice.com/joteke/ar...1/30/2493.aspx
though it does a postback based on the row which was clicked and you can do
anything in the postback event (you probably need direct linking), however
if postback is not an issue then why not.
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"botham782" <> wrote in message
news: oups.com...
> 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
>