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

ItemDataBound can't change the values

2 Answers 255 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henrik Tegman
Top achievements
Rank 1
Henrik Tegman asked on 18 Jun 2010, 03:41 PM
Hi,

I have a RadGrid and it get popultated from a view, but I want to stop it as it inserts into one of the colums and I want todo some things here, and I can get the event and I can find everything I find my value that I want to change, but after chaneing it nothing happends.

My guess is that it has either already been bound, or that I have to rebind the grid or something similar so I hope I could get an answer here. Some of my sample code and what I want todo, maybe someone has a better ide on how to handle the problem.

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

{

 

 

    if (e.Item is GridDataItem)
   {

 

    GridDataItem dataItem = (GridDataItem)e.Item;

 

    DataRowView groupDataRow = (DataRowView)e.Item.DataItem;

 

    string test = groupDataRow.Row.ItemArray[1].ToString();

 

    groupDataRow.Row.ItemArray[1] = "testing";

 

    }

}

Now this simple code is just used for testing as you can guess, if I put a break there I can see all the values fine, the string called test gets the right value and everything, but I then try to change the groupDataRow.Row.ItemArray[1] = "testing"; nothing happens, it doesn't crash but the grid still has the old value that I can see in my test string.

What I want todo here is to simply replace the string with a link, I have a method that will get my link and it should only do that so a psedocode would look something like:

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

{

 

 

    if (e.Item is GridDataItem)

    {

 

 

    GridDataItem dataItem = (GridDataItem)e.Item;

 

    DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
    Hyperlink link = CreateLink(groupDataRow.Row.ItemArray[3]);

 

    groupDataRow.Row.ItemArray[1] = link; 

    }

}

This would then use one of the values to create the link and then I would simply replace the text with that link, where the CreateLink function would set the correct link and text for it. Maybe there is another way todo this, but as I said this grid is bound to a sqlview, maybe you can do links or hrefs there, I don't know tbh.

Thanks for any help!

 

 
Edit: The formating on the code looks strange, but I hope you can live with that since I can't change it..

 

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Jun 2010, 01:45 PM
Hello Henrik,

 You can achieve this by accessing the corresponding cell by using ColumnUniqueName of GridDataItem. Check out the following code snippet.

C#:
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            DataRowView groupDataRow = (DataRowView)e.Item.DataItem; 
            string test = groupDataRow.Row.ItemArray[1].ToString(); 
            dataItem["ColumnUniqueName"].Text = "testing"
        } 
    } 

Thanks,
Princy.

0
Henrik Tegman
Top achievements
Rank 1
answered on 21 Jun 2010, 02:46 PM
Thank you very much.

I should have posted that I had finished this problem myself and I did just like you suggested.
Tags
Grid
Asked by
Henrik Tegman
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Henrik Tegman
Top achievements
Rank 1
Share this question
or