Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast string array to Type in C#

I'm using ASPxGridView PerformCallback method to pass javascript value to behind code, it works. But I need to cast or convert string array in type and bind into ASPxGridView. How can I do it?

  protected void detailGrid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        Group [] data = (Group)e.Parameters.Split(';');

        List<Group> l = new List<Group>();
        for (int i = 0; i < data.Length; i++)
        {
            l.Add(data[i]);
        }

        XFGridView1.DataSource = data;
        XFGridView1.DataBind();

    }
like image 553
askingPPl Avatar asked Feb 19 '26 05:02

askingPPl


1 Answers

LINQ works fine for "converting" or "selecting":

IEnumerable<Group> data = e.Parameters.Split(';').Select(p=>new Group(p));  
//or
IEnumerable<Group> data = e.Parameters.Split(';').Select(p=>new Group{SomeProperty=p});

assuming your Group class has a constructor that takes the string value or some property you wish to populate, respectively.

like image 81
markt Avatar answered Feb 20 '26 18:02

markt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!