This is a migrated thread and some comments may be shown as answers.

Value of cell always "&nbsp" on OnItemCreated

5 Answers 404 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johan
Top achievements
Rank 1
Johan asked on 23 Jan 2012, 09:13 PM
Hi,

I bind my grid programmatically during the NeedDataSource event which is in turn a SQLDataSource instance:


protected void grdMyGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
   ((RadGrid)sender).DataSource = sqlDs;
}

From here I’m trying to check if the value of a specific cell match a condition during the ItemCreated event:

protected void grdMyGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
     if (e.Item is GridDataItem)
      {
          var item = e.Item as GridDataItem;
           if (item["ValidationState"].Text == "UNMATCHED")
           {
              item.BackColor = System.Drawing.Color.Red;
              item.ForeColor = System.Drawing.Color.White;
           }
      }
 }

For some reason the value of item[“ValidationState”].Text is always "&nbsp" as so is any other cell I’m trying to access via the UniqueName property. And yes, they are explicitly defined in my markup of the columns.

It is maybe becuase I bind the grid during NeedDataSource and not at design time with the DataSourceID property specified? Or perhaps other suggestion or solutions?

Thanks for you help!

5 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 23 Jan 2012, 09:28 PM
do you use GridBoundColumn
if you use a GridTemplateItem you will need to tease the control out from the correct TableCell
0
Johan
Top achievements
Rank 1
answered on 23 Jan 2012, 09:32 PM
Yes I'm using GridBoundColumn:

<telerik:GridBoundColumn DataField="ValidationState" DataType="System.String" FilterControlAltText="Filter column column"
                        HeaderText="Status" UniqueName="ValidationState" ShowSortIcon="true" AllowSorting="true"
                        ShowFilterIcon="true" AllowFiltering="true">
                        <HeaderStyle Width="100px" />
</telerik:GridBoundColumn>
0
Elliott
Top achievements
Rank 2
answered on 23 Jan 2012, 10:37 PM
try to see if you can put your code in the ItemDataBound event handler
I don't think the ItemCreated has data yet
0
Shinu
Top achievements
Rank 2
answered on 24 Jan 2012, 05:15 AM
Hello Ryno,

ItemCreated is fired before the item is data-bound. So there is no data in the cells' text or input controls. Try accessing the same in ItemDataBound event. Also take a look at the following help documentation.
Distinguishing the major differences between ItemCreated and ItemDataBound events.

-Shinu.
0
Johan
Top achievements
Rank 1
answered on 28 Jan 2012, 05:04 PM
Hi Shinu,

Thank you very much for pointing that out!

It was indeed the problem with my code. Moving my logic to the ItemDataBound event solved it for me.

Regards
Tags
Grid
Asked by
Johan
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Johan
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or