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

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

1 Answer 578 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gold Systems
Top achievements
Rank 1
Gold Systems asked on 13 Sep 2016, 05:40 PM

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"
        OnNeedDataSource="grdAddresses_NeedDataSource"
        OnBatchEditCommand="grdAddresses_BatchEditCommand"
        OnPreRender="grdAddresses_PreRender"
        EnableViewState="true"
        AllowSorting="false"
        AllowPaging="false" >
      <MasterTableView EditMode="Batch" BatchEditingSettings-EditType="Row">
        <Columns>
          <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" UniqueName="DeleteColumn"
              ImageUrl="~/Images/clear-button-24x24.png"
              HeaderStyle-Width="4%" ></telerik:GridButtonColumn>
          <telerik:GridTemplateColumn HeaderText="Type*" DataField="TypeUid" UniqueName="Type" >
            <ItemTemplate>
              <asp:Label runat="server" />
            </ItemTemplate>
            <EditItemTemplate>
              <telerik:RadDropDownList ID="ddlType" runat="server" DataTextField="DropDownListText" DataValueField="Uid" DataFied="TypeUid" >
              </telerik:RadDropDownList>
            </EditItemTemplate>
          </telerik:GridTemplateColumn>
          <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" >
            <ItemTemplate>
              <asp:Label runat="server" Text='<%# Eval("CountryUid") %>' />
            </ItemTemplate>
            <EditItemTemplate>
              <telerik:RadDropDownList ID="ddlCountry" runat="server"
                  DataTextField="DropDownListText" DataValueField="Uid" OnClientSelectedIndexChanged="countrySelectedIndexChanged" >
              </telerik:RadDropDownList>
            </EditItemTemplate>
          </telerik:GridTemplateColumn>
          <telerik:GridTemplateColumn HeaderText="State" DataField="StateUid" UniqueName="State" >
            <ItemTemplate>
              <asp:Label runat="server" Text='<%# Eval("StateUid") %>' />
            </ItemTemplate>
            <EditItemTemplate>
              <telerik:RadDropDownList ID="ddlState" runat="server" OnClientItemsRequesting="stateItemsRequesting"
                  OnClientSelectedIndexChanged="stateSelectedIndexChanged" >
              </telerik:RadDropDownList>
            </EditItemTemplate>
          </telerik:GridTemplateColumn>
          <telerik:GridBoundColumn HeaderText="Postal Code" DataField="PostalCode" />
          <telerik:GridTemplateColumn HeaderText="County" DataField="CountyUid" UniqueName="County" >
            <ItemTemplate>
              <asp:Label runat="server" Text='<%# Eval("CountyUid") %>' />
            </ItemTemplate>
            <EditItemTemplate>
              <telerik:RadDropDownList ID="ddlCounty" runat="server" OnClientItemsRequesting="countyItemsRequesting" >
              </telerik:RadDropDownList>
            </EditItemTemplate>
          </telerik:GridTemplateColumn>
        </Columns>
      </MasterTableView>
    </telerik:RadGrid>

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 16 Sep 2016, 01:12 PM
Hello,

The secret property you are looking for is SelectedValue. You can use it with binding expressions:
http://msdn.microsoft.com/en-us/library/vstudio/ms178366(v=vs.100).aspx

Since you are using it within an EditItemTemplate, the choise would be Bind. You can check the following live sample for a practical implementation:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

I hope this will prove helpful.

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