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

GridDropDownColumn: Pull a list not included in DataSource

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 07 Aug 2014, 07:07 PM
So I have a RadGrid:

<telerik:RadGrid ID="RadGridPageDetails" runat="server" DataSourceID="dsReportPageDetail" AllowAutomaticUpdates="True" Width="100%" OnItemCommand="RadGridPageDetails_ItemCommand" OnItemDataBound="RadGridPageDetails_ItemDataBound"><br>
    <
MasterTableView AutoGenerateColumns="False" DataKeyNames="ReportPageID" DataSourceID="dsReportPageDetail">


A bunch of Gridbound columns like so:

<telerik:GridBoundColumn DataField="PageName" FilterControlAltText="Filter PageName column" HeaderText="Section Name" SortExpression="PageName" UniqueName="PageName">
    <ColumnValidationSettings>
        <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
</
telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PageTitle" FilterControlAltText="Filter PageTitle column" HeaderText="Section Title" SortExpression="PageTitle" UniqueName="PageTitle">
    <ColumnValidationSettings>
        <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
</telerik:GridBoundColumn>

Here I Created a GripDropDownColumn inside that RadGrid:

<telerik:GridDropDownColumn DataField="PageOrientation" EnableEmptyListItem="true" EmptyListItemText="--Select--" EmptyListItemValue="" ListTextField="Value" ListValueField="Value" FilterControlAltText="Filter PageOrientation column" HeaderText="Page Orientation" UniqueName="PageOrientation">
<ColumnValidationSettings>
                      <ModelErrorMessage Text="" />
</ColumnValidationSettings>
</telerik:GridDropDownColumn>

And here I attempt to use codebehind to populate this griddropdowncolumn with the following values: Select, Landscape, Portrait. 

protected void RadGridPageDetails_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                GridEditManager editMan = editedItem.EditManager;
 
                GridDropDownListColumnEditor editor = editMan.GetColumnEditor("PageOrientation") as GridDropDownListColumnEditor;
                DataTable dt = new DataTable();
                dt.Load(SQLCalls.GetDropdownListValues("Page Orientation")); //This pulls "Landscape" and "Portrait"
                editor.DataSource = dt;
                editor.DataSource = new string[] { "Landscape", "Portrait" };
            }
        }

Both of the datasources I've tried don't work, and I believe it's because I'm not setting ListText and ListValue correctly. Can someone help me fix this so it will work?

Also, when I am in edit mode, I want it to start off selecting the current value, instead of defaulting to "Select".


2 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 07 Aug 2014, 07:10 PM
I don't know how to edit so here goes:

A detail I forgot to mention, the current datasource will insert the gridcolumns into another table, and it will insert "Portrait" or "Landscape" as a text into that table. The Insert, Update, Select queries come from the sqldatasource declared by the Radgrid "dsReportPageDetail"

Basically I want to have a second datasource to pull options for page orientation.
0
Shinu
Top achievements
Rank 2
answered on 08 Aug 2014, 06:10 AM
Hi Jason,

I guess you want to bind the GridDropDownColumn with a different datasource in edit mode. If you are binding from code behind, do it entirely from server side. Check this help documentation for more help,
Customize/Configure GridDropDownColumn
Another suggestion is you can use GridTemplateColumn, with DropDownList in ItemTemplate with one DataSource and in EditItemTemplate the DropDownList with another datasource and perform the required operation. To set the selected row in edit mode, try the following code snippet:

C#:
editor.SelectedValue = DataBinder.Eval(editedItem.DataItem, "PageOrientation").ToString();

Thanks,
Shinu
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or