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

Sorting on RadGrid RadComboBox/Label Template Column

1 Answer 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lannity
Top achievements
Rank 1
Lannity asked on 25 Mar 2015, 08:22 PM
Hi,

I want to setup a RadGrid Object with batch editing using multiple disconnected DataTable data sources. How do I making sorting work as it should on in the Template Columns containing RadComboBox/Label controls? The columns I want to sort alphabetically in the example below are EntrĂ©e, and Salad.

Rad Grid aspx:

001.<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TesterApp.Default" %>
002.<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
003.</asp:Content>
004.<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
005.    <form id="form1" runat="server">
006.             <asp:Label ID="GridStatusLabel" runat="server" Text="Nothing Yet" ForeColor="#33CC33"></asp:Label>
007.<br />
008.      <telerik:RadScriptManager ID="RadScriptManager1" runat="server"/>
009. 
010.      <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" MinDisplayTime="1000" Skin="Silk">
011.      </telerik:RadAjaxLoadingPanel>
012. 
013.      <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel">
014.         <AjaxSettings>
015. 
016.            <telerik:AjaxSetting AjaxControlID="SampleGrid">
017.               <UpdatedControls>
018.                  <telerik:AjaxUpdatedControl ControlID="SampleGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
019.                  <telerik:AjaxUpdatedControl ControlID="GridStatusLabel"/>
020.               </UpdatedControls>
021.            </telerik:AjaxSetting>
022. 
023.         </AjaxSettings>
024.      </telerik:RadAjaxManager>
025. 
026.      <telerik:RadGrid
027.         ID="SampleGrid"
028.         runat="server"
029.         AllowPaging="True"
030.         AllowSorting="True"
031.         ShowStatusBar="True"
032.         GroupPanelPosition="Top"
033. 
034.         AllowAutomaticUpdates="True"
035.         AllowAutomaticInserts="True"
036.         AllowAutomaticDeletes="True"
037. 
038.         OnNeedDataSource="SampleGrid_NeedDataSource"
039. 
040.         OnItemCommand="SampleGrid_ItemCommand"
041.         OnItemDataBound="SampleGrid_ItemDataBound"
042.         OnBatchEditCommand="SampleGrid_BatchEditCommand"
043. 
044.         Skin="Silk"
045.         Height="467px"
046.      >
047.           <MasterTableView
048.             DataKeyNames="PersonID"
049.             AutoGenerateColumns="false"
050.             EditMode="Batch"
051.             CommandItemStyle-Wrap="false" ItemStyle-Wrap="false"
052.             CommandItemDisplay="TopAndBottom"
053.             CommandItemSettings-ShowExportToExcelButton="true"
054.             CommandItemSettings-ShowExportToPdfButton="true"
055.            >
056.               <BatchEditingSettings
057.                   EditType="Cell"
058.                   OpenEditingEvent="DblClick"
059.                />
060.                    <Columns>
061.                        <telerik:GridBoundColumn
062.                            UniqueName="rgcPersonID"
063.                            DataField="PersonID"
064.                            DataType="System.Int32"
065.                            Display="False"
066.                        >
067.                        </telerik:GridBoundColumn>
068. 
069.                        <telerik:GridBoundColumn
070.                            UniqueName="rgcFirst"
071.                            DataField="First"
072.                            HeaderText="First Name"
073.                            >
074.                        </telerik:GridBoundColumn>
075. 
076.                        <telerik:GridBoundColumn
077.                            UniqueName="rgcInitial"
078.                            DataField= "Initial"
079.                            HeaderText="Mid Initial"
080.                            >
081.                        </telerik:GridBoundColumn>
082. 
083.                        <telerik:GridBoundColumn
084.                            UniqueName="rgcLast"
085.                            DataField= "Last"
086.                            HeaderText="Last Name"
087.                            >
088.                        </telerik:GridBoundColumn>
089. 
090.                        <telerik:GridBoundColumn
091.                            UniqueName="rgcProfession"
092.                            DataField= "Profession"
093.                            HeaderText="Profession"
094.                            ItemStyle-Wrap="false"
095.                            >
096.                        </telerik:GridBoundColumn>
097. 
098.                        <telerik:GridTemplateColumn
099.                            UniqueName="rgcEntree"
100.                            HeaderText="Entree"
101.                            HeaderToolTip="This person's favorite meal, of course!"
102.                            DataField="EntreeID"
103.                            AllowSorting="true"
104.                            SortExpression="EntreeID"
105.                            HeaderStyle-Width="90"
106.                            ItemStyle-Width="50px"
107.                            ItemStyle-HorizontalAlign="Center"
108.                            HeaderStyle-HorizontalAlign="Center"
109.                            Resizable="false"
110.                            ItemStyle-Wrap="false"
111.                        >
112.                            <ItemTemplate>
113.                                <asp:Label ID="lblEntree" runat="server" Text='<%# Eval("EntreeFaveID")%>' ></asp:Label>
114.                            </ItemTemplate>
115.                            <EditItemTemplate>
116.                                <telerik:RadComboBox
117.                                    UniqueName="rcbunEntree"
118.                                    ID="rcbidEntreeID"
119.                                    DataValueField="EntreeID"
120.                                    DataTextField="Name"
121.                                    runat="server"
122.                                    OnPreRender="rcbidEntreeID_PreRender"
123.                                    >
124.                                </telerik:RadComboBox>
125.                            </EditItemTemplate>
126.                        </telerik:GridTemplateColumn>
127. 
128.                        <telerik:GridTemplateColumn
129.                            UniqueName="rgcSalad"
130.                            HeaderText="Salad"
131.                            HeaderToolTip="I think it's healthy."
132.                            DataField="SaladID"
133.                            AllowSorting="true"
134.                            SortExpression="SaladID"
135.                            HeaderStyle-Width="90"
136.                            ItemStyle-Width="50px"
137.                            ItemStyle-HorizontalAlign="Center"
138.                            HeaderStyle-HorizontalAlign="Center"
139.                            Resizable="false" ItemStyle-Wrap="false"
140.                        >
141.                            <ItemTemplate>
142.                                <asp:Label ID="lblSalad" runat="server" Text='<%# Eval("SaladFaveID")%>' ></asp:Label>
143.                            </ItemTemplate>
144.                            <EditItemTemplate>
145.                                <telerik:RadComboBox
146.                                    UniqueName="rcbunSalad"
147.                                    ID="rcbidSaladID"
148.                                    DataValueField="SaladID"
149.                                    DataTextField="Name"
150.                                    runat="server"
151.                                    OnPreRender="rcbidSaladID_PreRender"
152.                                    >
153.                                </telerik:RadComboBox>
154.                            </EditItemTemplate>
155.                        </telerik:GridTemplateColumn>
156. 
157.                        <telerik:GridTemplateColumn
158.                            UniqueName="rgcDateFaveEaten"
159.                            AllowSorting="true"
160.                            ItemStyle-HorizontalAlign="Center"
161.                            HeaderStyle-HorizontalAlign="Center"
162.                            HeaderText="Last Meal Date"
163.                            SortExpression="rgcDateFaveEaten"
164.                            >
165.                            <ItemTemplate>
166.                                <asp:Label runat="server" ID="lblDateFaveEaten" Text='<%# Eval("DateFaveEaten", "{0:MM/dd/yyyy}") %>'>
167.                                </asp:Label>
168.                            </ItemTemplate>
169.                            <EditItemTemplate>
170.                                <telerik:RadDatePicker ID="rdpDateFaveEaten" runat="server" Width="100">
171.                                </telerik:RadDatePicker>
172.                            </EditItemTemplate>
173.                        </telerik:GridTemplateColumn>
174.                    </Columns>
175.            </MasterTableView>
176. 
177.            <ClientSettings
178.                AllowKeyboardNavigation="True"
179.                EnableRowHoverStyle="true"
180.            >
181.            <ClientEvents OnCellSelected=""/>
182.                <Selecting AllowRowSelect="True" CellSelectionMode="SingleCell" />
183.                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
184.                <Resizing AllowColumnResize="True" ClipCellContentOnResize="true" ResizeGridOnColumnResize="false" />
185.            </ClientSettings>
186.            <PagerStyle Height="40px" />
187. 
188.            <FilterMenu EnableEmbeddedSkins="True" Skin ="Silk"></FilterMenu>
189.        </telerik:RadGrid>
190.    </form>
191.</asp:Content>


Code Behind:

001.using System;
002.using System.Data;
003.using System.Linq;
004.using Telerik.Web.UI;
005.using System.Web.UI.WebControls;
006. 
007.namespace TesterApp {
008. 
009.    public partial class Default : System.Web.UI.Page
010.    {
011.        private DataTable Foodies = new DataTable("FoodLiker");
012.        private DataTable Entrees = new DataTable("Entree");
013.        private DataTable Salads = new DataTable("Salad");
014. 
015.        protected void Page_Load(object sender, EventArgs e)
016.        {
017.            Entrees.Columns.Add("EntreeID", typeof(Int32));
018.            Entrees.Columns.Add("Name", typeof(string));
019.            Entrees.Columns.Add("Description", typeof(string));
020. 
021.            Salads.Columns.Add("SaladID", typeof(Int32));
022.            Salads.Columns.Add("Name", typeof(string));
023.            Salads.Columns.Add("Description", typeof(string));
024. 
025.            Foodies.Columns.Add("PersonID",      typeof(Int32));
026.            Foodies.Columns.Add("First",         typeof(string));
027.            Foodies.Columns.Add("Initial",       typeof(char));
028.            Foodies.Columns.Add("Last",          typeof(string));
029.            Foodies.Columns.Add("Profession",    typeof(string));
030.            Foodies.Columns.Add("EntreeFaveID",    typeof(Int32));
031.            Foodies.Columns.Add("SaladFaveID",     typeof(Int32));
032.            Foodies.Columns.Add("DateFaveEaten", typeof(string));
033. 
034.            Entrees.Rows.Add(100, "No Entree Chosen", "Choose, or Lose. It's how you play the game.");
035.            Entrees.Rows.Add(111, "Spicy Honey-Brushed Chicken Thighs", "Habanero Flavored Chicken Pieces Dipped in Blended Comb Scraped Off with a Denman Grooming Brush");
036.            Entrees.Rows.Add(222, "Easy Baked Fish Fillets", "Preschool Bag of Cod Pieces Made to Prepare with a Ten Watt Light Bulb");
037.            Entrees.Rows.Add(333, "Spaghetti with Sausage and Tomato Sauce", "Pasta Pushed through a Struddler with Chunks of Imitation Meat Substitute and Ketchup");
038.            Entrees.Rows.Add(444, "Miso-Glazed Salmon", "Salmon in a Bowl of Miso Soup");
039.            Entrees.Rows.Add(555, "Chicken Cordon Bleu", "Fancy Poultry Slices Eaten with Your Pinky Finger Sticking Out");
040.            Entrees.Rows.Add(666, "Shrimp and Broccoli Stir-Fry", "Sea Creatures Curled up with Flakey Plastic Tails with Pieces of Broccoli Mixed together with a Paddle inside a Fryolater");
041. 
042.            Salads.Rows.Add(80, "No Salad Chosen",    "Choose Your Destiny");
043.            Salads.Rows.Add(81, "Jello Salad",    "I think this was in a Bill Cosby Commercial");
044.            Salads.Rows.Add(82, "Ambrosia",       "A Salad if it Was Bought in a Candy Store");
045.            Salads.Rows.Add(83, "Celery Victor""Named after the Guy");
046.            Salads.Rows.Add(84, "Coleslaw",       "Mixed with Original Recipe Chicken, you Have Soggy Sweet Chicken");
047.            Salads.Rows.Add(85, "Crab Louie",     "Under the Sea, Everything's Better, Everything's Wetter, Take it from Me");
048.            Salads.Rows.Add(86, "Glorified Rice", "I Thought this was Supposed to be a Salad");
049. 
050.            Foodies.Rows.Add(10000, "Jim",      "K",   "TheJay",     "Filmographer",                         333, 82,"1/10/2015");
051.            Foodies.Rows.Add(20000, "Kevin",    null"Slevin",     "Step Dancer",                          222, 86,"1/10/2015");
052.            Foodies.Rows.Add(30000, "Cathleen", "M",   "Fuhrsberg""Colecovision Repair Dude",             555, 82,"1/10/2015");
053.            Foodies.Rows.Add(40000, "Trey",      null, "Chase",      "Salesman of the Year",                 666, 81,"1/10/2015");
054.            Foodies.Rows.Add(50000, "Chevy",     "B""Taylor",     "Professional Rumorist",                222, 82,"1/10/2015");
055.            Foodies.Rows.Add(60000, "Lance",     "K""Simmons",    "The One Who's Got it All Figured Out", 111, 86,"1/10/2015");
056.            Foodies.Rows.Add(70000, "Sandy",     null, "Seekleston", "Brainwashing Machine Repair Man",      222, 83,"1/10/2015");
057.        }
058. 
059.        protected void SampleGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
060.        {
061.            SampleGrid.DataSource = Foodies;
062.        }
063. 
064.        protected void SampleGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
065.        {
066.            if (e.CommandName == "DeleteRecord")
067.            {
068.                GridStatusLabel.Text = "Deleted a Record.";
069.            }
070.        }
071. 
072.        protected void SampleGrid_BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e)
073.        {
074.            foreach (GridBatchEditingCommand command in e.Commands)
075.            {
076.                switch (command.Type)
077.                {
078.                    case GridBatchEditingCommandType.Update:
079.                        GridStatusLabel.Text = "Update a Record from Batch Edit";
080.                    break;
081.                    case GridBatchEditingCommandType.Insert:
082.                        GridStatusLabel.Text = "Insert a Record from Batch Edit";
083.                    break;
084.                    case GridBatchEditingCommandType.Delete:
085.                        GridStatusLabel.Text = "Delete a Record from Batch Edit";
086.                    break;
087.                }
088.            }
089.        }
090. 
091.        protected void SampleGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
092.        {
093.            if (e.Item is GridDataItem)
094.            {
095.             // Setup Handlers for the Grid Data
096.                GridDataItem dataItem = e.Item as GridDataItem;
097.                Label lbl;
098. 
099.             // Populate the Entree Drop Down
100.                lbl = (Label)dataItem["rgcEntree"].FindControl("lblEntree");
101.                if (lbl != null) {
102.                    if (lbl.Text.Length <= 0)
103.                        lbl.Text = "100";
104. 
105.                    Entrees.PrimaryKey = new DataColumn[] { Entrees.Columns["EntreeID"] };
106.                    DataRow currentRecordRow = Entrees.Rows.Find(Convert.ToInt32(lbl.Text));
107.                    lbl.Text = currentRecordRow["Name"].ToString();
108.                }
109. 
110.             // Populate the Salad Drop Down
111.                lbl = (Label)dataItem["rgcSalad"].FindControl("lblSalad");
112.                if (lbl != null) {
113.                    if (lbl.Text.Length <= 0)
114.                        lbl.Text = "100";
115. 
116.                    Salads.PrimaryKey = new DataColumn[] { Salads.Columns["SaladID"] };
117.                    DataRow currentRecordRow = Salads.Rows.Find(Convert.ToInt32(lbl.Text));
118.                    lbl.Text = currentRecordRow["Name"].ToString();
119.                }
120. 
121.            }
122.        }
123. 
124.        protected void rcbidEntreeID_PreRender(object sender, EventArgs e)
125.        {
126.            RadComboBox combo = sender as RadComboBox;
127. 
128.            combo.DataSource = Entrees;
129.            combo.DataValueField = "EntreeID";
130.            combo.DataTextField = "Name";
131.            combo.ToolTip = "Description";
132.            combo.DataBind();
133.        }
134. 
135.        protected void rcbidSaladID_PreRender(object sender, EventArgs e)
136.        {
137.            RadComboBox combo = sender as RadComboBox;
138. 
139.            combo.DataSource = Salads;
140.            combo.DataValueField = "SaladID";
141.            combo.DataTextField = "Name";
142.            combo.ToolTip = "Description";
143.            combo.DataBind();
144.        }
145.    }
146.}

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 30 Mar 2015, 08:00 AM
Hi Lannity,

Can you please refer to the answer in the support ticket that you have opened regarding the same issue: ticket ID: 921033.

If you have any other questions, I would suggest that we continue the conversation in the support ticket.


Best Regards,
Konstantin Dikov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Lannity
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or