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

Assigning array to datafield?!

1 Answer 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajz
Top achievements
Rank 1
Rajz asked on 14 Oct 2010, 01:53 PM

Hello,

Observe the code snippet below:

public
class MyItem

 

{

    public int value1 { get; set; }

    public int value2 { get; set; }
    public int?[] dateids {get;set;}

    public MyItem()
    {
        dateids=new int?[4];
    }

}

public class MyItems : CollectionBase

 

{

    public int Add(MyItem item)

    {

        return List.Add(item);

    }

    public void Remove(MyItem item)

    {

        List.Remove(item);

    }

    public int IndexOf(MyItem item)

    {

        return List.IndexOf(item);

    }

    public MyItem this[int index]

    {

        get { return (MyItem)List[index]; }

        set { List[index] = value; }

    }

}

I set instance of MyItems to DataSource property of grid.
How do I assign dateids to grid's DataField?

Any workaround would be much appreciated

Thank you

Regards
Raj

1 Answer, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 20 Oct 2010, 08:33 AM
Hi Raj,

The RadGrid does not support the desired functionality, however you could try getting the values from dateids into the RadGrid's ItemDataBound event handler and build string which you could assign to the RadGrid's cell:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
       GridDataItem item = e.Item as GridDataItem;
       int?[] dateids = (item.DataItem as MyItem).dateids;
       item["dateids"].Text = "";
       string text = "";
       foreach (int i in dateids)
       {
           text += i.ToString() + ",";
       }
       int count = text.Length - 1;
       item["dateids"].Text = text.Remove(count, 1);
    }
}

Additionally I am sending you a simple example, please check it out and let me know if it helps you.

Regards,
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
Tags
Grid
Asked by
Rajz
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or