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

Data in GridTemplateColumn not updating

3 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DuelingCats
Top achievements
Rank 2
DuelingCats asked on 09 Aug 2012, 03:11 PM
I have a RadGrid on my page with the last data column being a GridTemplateColumn with a RadComboBox inside of it. I have been going by this example here to help familiarize myself with the RadGrid control. I know there is a DropDown column type, but I want to try and get this TemplateColumn working.

Whenever I click update on a row, my RadComboBox has the list of different Frequencies and has the proper one selected. When I select a different frequency and click update again to save those changes, the frequency isn't saved. It is still the previous one.

I have attached a picture of my model. OpenAccessDataSource is Task while FrequencyDS is TaskFrequency.

Here is my grid:
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" GridLines="None"
    AutoGenerateEditColumn="True" DataSourceID="OpenAccessDataSource"
    AllowAutomaticUpdates="True">
    <MasterTableView AutoGenerateColumns="False"
        DataSourceID="OpenAccessDataSource" DataKeyNames="Id">
        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column"
                HeaderText="Id" SortExpression="Id" UniqueName="Id">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="TaskName" FilterControlAltText="Filter TaskName column"
                HeaderText="TaskName" SortExpression="TaskName" UniqueName="TaskName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="NextRun" FilterControlAltText="Filter NextRun column"
                HeaderText="NextRun" SortExpression="NextRun" UniqueName="NextRun">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Enabled" DataType="System.Char" FilterControlAltText="Filter Enabled column"
                HeaderText="Enabled" SortExpression="Enabled" UniqueName="Enabled">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Frequency" DataField="Frequency" UniqueName="Frequency">
                <ItemTemplate>
                    <%# DataBinder.Eval(Container.DataItem, "Frequency") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadComboBox runat="server" ID="FrequencyCB" DataTextField="Name" DataValueField="Name" DataSourceID="FrequencyDS"
                     SelectedValue='<%# DataBinder.Eval(Container.DataItem, "Frequency") %>' />
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
DuelingCats
Top achievements
Rank 2
answered on 13 Aug 2012, 11:48 AM
bump
0
Kostadin
Telerik team
answered on 14 Aug 2012, 03:33 PM
Hello,

Thank you for contacting us.

In a RadGrid with an ItemTemplate and EditItemTemplate  if you use Bind or Eval in the ItemTemplate , there will be no difference. If you use Eval in the EditItemTemplate , the value will not be able to be passed to the Update method of the DataSource that the grid is bound to. In order to save the changes you should use Bind().
<telerik:GridTemplateColumn HeaderText="Frequency" DataField="Frequency" UniqueName="Frequency">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Frequency") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="FrequencyCB" DataTextField="Name" DataValueField="Name" DataSourceID="FrequencyDS"
SelectedValue='<%# Bind("Frequency") %>' />
</EditItemTemplate>
</telerik:GridTemplateColumn>

I hope this information helps.

Kind regards,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
DuelingCats
Top achievements
Rank 2
answered on 15 Aug 2012, 02:03 PM
Thanks Kostadin. That makes sense.
Tags
Grid
Asked by
DuelingCats
Top achievements
Rank 2
Answers by
DuelingCats
Top achievements
Rank 2
Kostadin
Telerik team
Share this question
or