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

LINQ in Heirarchy

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ulysses
Top achievements
Rank 1
Ulysses asked on 20 Jun 2010, 10:57 AM

Hi, I want to use LINQ in the creation of heirarchy in radgrid, but to no avail, i can't solve.

Here is my snippet.

-------- .cs code-behind -----

// select from dropdownlist, then click button
protected void cmdView_Click(object sender, EventArgs e)
        {
            if (cmbItem.SelectedItem.Text != string.Empty)
            {               
                this.radExpand.Rebind();
            }
        }

// itemID is being fetched from dropdownlist
 void radExpand_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            DataModelDataContext context = new DataModelDataContext();
            if (cmbItem.SelectedItem.Text != string.Empty)
            {
                Guid teacherID = new Guid(cmbItem.SelectedValue);
                var data = from d in context.inventoryItems where d.itemID== itemIDselect d;
                this.radExpand.DataSource = data;
            }
        }

--------------------- .aspx markup -------------------------
<telerik:RadGrid runat="server" ID="radExpand" AllowPaging="True" GridLines="None" PageSize="30" AutoGenerateColumns="False" ShowFooter="True" ShowGroupPanel="false"
                ShowStatusBar="True" OnNeedDataSource="radExpand_NeedDataSource" onitemcreated="radExpand_ItemCreated">
                <MasterTableView>
                        <Columns>
                        <telerik:GridBoundColumn DataField="itemID" HeaderText="ID" UniqueName="itemID">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn HeaderText="Item Name" UniqueName="itemName">
                            <ItemTemplate>
                                <%# myProject.getItemName(Convert.ToString(DataBinder.Eval(Container.DataItem, "itemID"))).ToUpper() %>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="Status" HeaderText="Status">
                            <ItemTemplate>
                                <%# myProject.getStatus(new Guid(Convert.ToString(DataBinder.Eval(Container.DataItem, "itemID")))) %>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>

-----------------------------------------

Thank you.

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 24 Jun 2010, 09:23 AM
Hi Ulysses,

You can use the same approach as the one demonstrated in this online demo. However you will need to change the actual data retrieval with call to your LINQ data context.

All the best,
Rosen
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
Ulysses
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or