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

RadGrid: GridTemplateColumn with RadComboBox not showing value in grid or insert/update

6 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 02 Oct 2014, 07:48 PM
I recently changed a regular GridBoundColumn to a GridTemplateColumn so that it may serve as a RadComboBox instead of a textbox which allows users to choose from a dropdownlist or type in their own value which can be dynamically saved to the list. I do this in the Insert/Update methods of the Radgrid which will update the tables for the dropdownlists just fine. However, the RadGrid itself no longer finds a value for the column and inserts NULL into its actual column. I will break it down

RadGridTable
Columns: ClaimantID, StartDate, EndDate, NoteStatus

RadComboBoxTable
Columns: NoteStatusID, Text, ect.

The RadGrid has an aspx sqldatasource with an Insert command into the RadGridTable. This worked perfectly fine.
I added a new OnInsertMethod through C# that will grab the value from RadComboBox and put it into the RadComboBoxTable. This now works fine but on insert and update the value NULL gets put into the RadGridTable. Every other value works just fine.

Here is my RadComboBox:




<telerik:GridTemplateColumn FilterControlAltText="Filter NoteStatus column" HeaderText="Note Status" SortExpression="NoteStatus" UniqueName="NoteStatus" Visible="true">
                                <ItemTemplate>
                                    <%#DataBinder.Eval(Container.DataItem,"NoteStatus") %>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox ID="rcbNoteStatus" runat="server" DataField="NoteStatus" Text='<%#DataBinder.Eval(Container.DataItem,"NoteStatus") %>' EnableLoadOnDemand="true" OnItemsRequested="rcbNoteStatus_ItemsRequested" DataTextField="Description" DataValueField="Status" ></telerik:RadComboBox> 
                                </EditItemTemplate>
 </telerik:GridTemplateColumn>

6 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 03 Oct 2014, 02:25 PM
I have tried moving the DataField="NoteStatus" from RadComboBox to GridTemplateColumn but it changed nothing.
0
Viktor Tachev
Telerik team
answered on 07 Oct 2014, 11:52 AM
Hi Jason,

If you would like to use a RadComboBox as an editor for a column you could also use a GridDropDownColumn and set its DropDownControlType to RadComboBox. In case you would like additional information on this column type check out the following article:

This said, if you prefer to use GridTemplateColumn check out the following articles that describe how you can bind a control nested inside EditItemTemplate. Check out the second article that illustrates how you can access controls placed in the GridTemplateColumn.



Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jason
Top achievements
Rank 1
answered on 13 Oct 2014, 07:10 PM
I would like to use a  GripDropDownColumn but I saw no example on how to hardcode the options. There are only two so I don't want to use the database and query it like a datasource and I'm not sure how to hardcode a datasource
0
Jason
Top achievements
Rank 1
answered on 13 Oct 2014, 07:14 PM
Sorry is it possible for more information? I've tried what the links have shown but they only work backwards instead of forward.

Right now, the RadGrid will show the value stored correctly. However, on Save it will save null instead of what's actually selected in the dropdown. How do I handle this?
0
Jason
Top achievements
Rank 1
answered on 13 Oct 2014, 08:29 PM
More specifically, my GridTemplateColumn has an EditColumn which contains a RadComboBox.

Now, in my aspx SQLDataSource, how do I access that control? 

My GridTemplateColumn has uniqueID "NoteStatus" but that gives me a null. How do I grab the radcombobox inside the gridtemplatecolumn? NOT IN THE C# side please
0
Viktor Tachev
Telerik team
answered on 16 Oct 2014, 01:25 PM
Hi Jason,

In an earlier post you mention that there are only two options. Did you mean that the RadComboBox will have only two options available? If this is the case you could define the options in the markup.

Additionally, you can set the SelectedValue property of the RadComboBox to be bound to the NoteStatus field. The markup would look similar to the following:

<telerik:GridTemplateColumn DataField="NoteStatus" HeaderText="Note Status" UniqueName="NoteStatus">
    <ItemTemplate>
        <asp:Label Text='<%# Eval("NoteStatus") %>' runat="server" />
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox runat="server" ID="cboCustomerID" SelectedValue='<%# Bind("NoteStatus") %>'>
            <Items>
                <telerik:RadComboBoxItem Text="Status 1" Value="1" />
                <telerik:RadComboBoxItem Text="Status 2" Value="2" />
            </Items>
        </telerik:RadComboBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

Alternatively, if the items in the RadComboBox are populated form a database, you could define a DataSource that will be used by the RadComboBox. You need to set the DataTextField and DataValueField properties of the combo to the corresponding fields in the database table. The approach will be similar to the one illustrated in this online demo.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or