GridTemplateColumn with a RadDropDownList in the EditItemTemplate does not have selected value of the DataField

2 posts, 0 answers
  1. Gold Systems
    Gold Systems avatar
    9 posts
    Member since:
    Feb 2009

    Posted 13 Sep 2016 Link to this post

    I have a RadGrid. In the RadGrid I have some GridTemplateColumns. In the EditItemTemplate I have a RadDropDownList. The GridTemplateColumn has a DataField defined. My expectation is that when the page loads that the RadDropDownList in the EditItemTemplate should have a SelectedValue that matches the DataField. But the SelectedValue is the default (blank) first item in the dropdown list.  As soon as I select something from the dropdown list everything is happy including the Label that is in the ItemTemplate shows the text value for the item I selected from the dropdown list. 

    It works if I use a GridDropDownColumn instead, but I cannot in this case as I need to trigger javascript stuff based on an item selected from the dropdown. 


    How do I make sure that when the page loads the dropdown list's selected value matches the column's DataField value?  It seems it should work this way automatically.


    <telerik:RadGrid ID="grdAddresses" runat="server" AutoGenerateColumns="false" DataKeyNames="Uid"
            AllowPaging="false" >
          <MasterTableView EditMode="Batch" BatchEditingSettings-EditType="Row">
              <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" UniqueName="DeleteColumn"
                  HeaderStyle-Width="4%" ></telerik:GridButtonColumn>
              <telerik:GridTemplateColumn HeaderText="Type*" DataField="TypeUid" UniqueName="Type" >
                  <asp:Label runat="server" />
                  <telerik:RadDropDownList ID="ddlType" runat="server" DataTextField="DropDownListText" DataValueField="Uid" DataFied="TypeUid" >
              <telerik:GridBoundColumn HeaderText="Address*" DataField="Address" />
              <telerik:GridBoundColumn HeaderText="Supplemental Address" DataField="AddressSupplemental" />
              <telerik:GridBoundColumn HeaderText="City/Locality" DataField="LocalityName" />
              <telerik:GridTemplateColumn HeaderText="Country" DataField="CountryUid" UniqueName="Country" >
                  <asp:Label runat="server" Text='<%# Eval("CountryUid") %>' />
                  <telerik:RadDropDownList ID="ddlCountry" runat="server"
                      DataTextField="DropDownListText" DataValueField="Uid" OnClientSelectedIndexChanged="countrySelectedIndexChanged" >
              <telerik:GridTemplateColumn HeaderText="State" DataField="StateUid" UniqueName="State" >
                  <asp:Label runat="server" Text='<%# Eval("StateUid") %>' />
                  <telerik:RadDropDownList ID="ddlState" runat="server" OnClientItemsRequesting="stateItemsRequesting"
                      OnClientSelectedIndexChanged="stateSelectedIndexChanged" >
              <telerik:GridBoundColumn HeaderText="Postal Code" DataField="PostalCode" />
              <telerik:GridTemplateColumn HeaderText="County" DataField="CountyUid" UniqueName="County" >
                  <asp:Label runat="server" Text='<%# Eval("CountyUid") %>' />
                  <telerik:RadDropDownList ID="ddlCounty" runat="server" OnClientItemsRequesting="countyItemsRequesting" >


  2. Eyup
    Eyup avatar
    4046 posts

    Posted 16 Sep 2016 Link to this post


    The secret property you are looking for is SelectedValue. You can use it with binding expressions:

    Since you are using it within an EditItemTemplate, the choise would be Bind. You can check the following live sample for a practical implementation:

    I hope this will prove helpful.

    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top