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

Set value of DataRowView

4 Answers 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
zach davis
Top achievements
Rank 1
zach davis asked on 03 May 2010, 04:55 PM
Hey Everyone,

I have hit a hard spot here.....I have no idea why this isn't working.

Code
DataRowView dataItem = (DataRowView)commandEventArgs.Item.DataItem; 
int _value= Convert.ToInt32(dataItem.Row["valueToRetrieve"]); 
dataItem.Row[NUMBER] = GetDisplay(value); 
NOTE: I have change some variable names for organizational purposes......

I don't know why this isn't working.  It has worked for me in the past.  Am i not calling a method I need to call.  I know the GetDisplay() returns the right value.  However, this isn't being displayed when the screen comes back up. 

Any thoughts....

Thanks,

-zd


4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 May 2010, 02:22 PM

Hi,

You can access the DataItem property only in ItemDataBound event of grid. I am not sure about in which event you are trying the code.

Have you tried calling Rebind() method of grid after setting the values?

-Shinu.

0
zach davis
Top achievements
Rank 1
answered on 04 May 2010, 03:12 PM
Shinu,

Thanks for response.  I should have specified before -- I am calling this code from with inside the ItemDataBound event.  I suppose I could call RebindGrid().  However, I don't think that would be good from within the itemdatabound event.  Would that create an infinite loop?

Thanks,

-zd
0
Radoslav
Telerik team
answered on 10 May 2010, 11:54 AM
Hello Zach,

Indeed, calling the Rebind() method into the RadGrid.ItemDataBound event handler will cause infinite loop.  Also to achieve the desired functionality you could try using the following code snippet:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
       DataRowView dataItem = (DataRowView)e.Item.DataItem;
       int _value = Convert.ToInt32(dataItem.Row["valueToRetrieve"]);
       (e.Item as GridDataItem)["ColumnUniqueName"].Text = GetDisplay(value).ToString();
   }
}

Additionally I am sending you a simple example which demonstrates the desired functionality.

I hope this helps.

Greetings,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
zach davis
Top achievements
Rank 1
answered on 10 May 2010, 03:13 PM
Radoslav,

Thanks for the update.  I have tried your solution and it in fact did work.  Thanks for the help.

Thanks,

-zd
Tags
Grid
Asked by
zach davis
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
zach davis
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or