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

Getting value from GridDropDownColumn when NOT in Edit mode

5 Answers 250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steele
Top achievements
Rank 1
Steele asked on 23 Nov 2010, 01:33 AM
Hi All,
I have the need to get the selected value from a GridDropDownColumn while the row is not in Edit mode.
My Grid is defined as :
<telerik:RadGrid ID="rgCriterias" runat="server" GridLines="None" OnDeleteCommand="rgCriterias_DeleteCommand"
    OnInsertCommand="rgCriterias_InsertCommand" OnItemCommand="rgCriterias_ItemCommand"
    OnItemDataBound="rgCriterias_ItemDataBound" OnNeedDataSource="rgCriterias_NeedDataSource"
    OnPreRender="rgCriterias_PreRender" OnUpdateCommand="rgCriterias_UpdateCommand"
    OnCreateColumnEditor="rgCriterias_CreateColumnEditor">
    <ClientSettings EnableRowHoverStyle="True">
        <Selecting AllowRowSelect="True" />
        <Scrolling AllowScroll="True" ScrollHeight="400px" UseStaticHeaders="True" />
    </ClientSettings>
    <MasterTableView DataKeyNames="Id,Version,CategoryId" AutoGenerateColumns="False"
        CommandItemDisplay="Top" EditMode="EditForms">
        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
        <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton">
                <HeaderStyle Width="8%" />
            </telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="Sequence" DataType="System.Int32" HeaderText="Sequence"
                UniqueName="Sequence" ReadOnly="True">
                <HeaderStyle Width="12%" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description">
                <HeaderStyle Width="15%" />
            </telerik:GridBoundColumn>
            <telerik:GridHTMLEditorColumn DataField="Notes" HeaderText="Notes" UniqueName="Notes"
                ConvertEmptyStringToNull="False">
                <HeaderStyle Width="20%" />
            </telerik:GridHTMLEditorColumn>
            <telerik:GridHTMLEditorColumn DataField="TypicalResponse" HeaderText="Typical Response"
                UniqueName="TypicalResponse" ConvertEmptyStringToNull="False">
                <HeaderStyle Width="20%" />
            </telerik:GridHTMLEditorColumn>
            <telerik:GridDropDownColumn DataField="RoleId" EmptyListItemText="-- Select Role --"
                EmptyListItemValue="-1" EnableEmptyListItem="True" HeaderText="Role" ListTextField="desc"
                ListValueField="code" UniqueName="Role">
                <HeaderStyle Width="10%" />
            </telerik:GridDropDownColumn>
            <telerik:GridNumericColumn DataField="Weighting" DataType="System.Decimal" DefaultInsertValue="0"
                EmptyDataText="0" HeaderText="Weighting" UniqueName="Weighting" DataFormatString="{0:###.00}">
                <HeaderStyle Width="10%" />
            </telerik:GridNumericColumn>
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column1"
                ButtonType="ImageButton" ConfirmDialogType="RadWindow">
                <HeaderStyle Width="5%" />
            </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn UniqueName="EditCommandColumn1">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default">
    </HeaderContextMenu>
</telerik:RadGrid>
I have a button I click that I then need to fill out an object with the selected rows data.  I am able to do so mostly by using the GridDataItem from the MasterTableView.GetSelectedItems(). From there, I access the .Text property of the table cell.
But with a GridDropDownColumn, I am after the Value of the dropdownlist item, not the Text.
How do I access this?
Thanks for any info.
Steele.

5 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 25 Nov 2010, 04:56 PM
Hi Steele,

When the row is in display mode, the DropDown control is not rendered. Therefore is not databound and you do not have the actual DataValues for this field. One possible solution is, since you can get the actual display text, you can make a query to the underlying data model and retrieve the actual value corresponding to this text. 

Regards,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Steele
Top achievements
Rank 1
answered on 29 Nov 2010, 12:13 AM
Thanks Marin, but this does not suit as it requires the Text element to be a unique data key within the dataset - which may not be the case.
Any other ideas?
Access to the Value field is a requirement for me.
Thanks,
Steele.
0
Marin
Telerik team
answered on 30 Nov 2010, 02:01 PM
Hi Steele,

You can use the DataKeyValues from the MasterTableView. This will give you the ID of the selected row. After that you can make a query that retrieves the field connected with combo box in the DropDownColumn for this record (i.e. the RoleId field). Here is code snippet showing this approach:

GridDataItem gridDataItem = RadGrid1.MasterTableView.GetSelectedItems()[0] as GridDataItem;
            int id = (int)RadGrid1.MasterTableView.DataKeyValues[gridDataItem.ItemIndex]["DataKeyName"];
//select the value of combo box field where dataKeyName field = id

Hope this helps. Let me know if you have any other questions.

Sincerely yours,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Steele
Top achievements
Rank 1
answered on 01 Dec 2010, 12:25 AM
This seems awfully long winded to retrieve data that has already been queried to bind to the grid.
Plus, if I go back to the DB to get the value, I am not guaranteed concurrency (as the underlying row may have been changed by another user since the last bind of the grid).
I think I will need to create a template column here to fill this gap. Using a hidden and bound textbox to store the value along with the visible label for displaying the text. That way I can get the data directly.
Does this seem feasible to you?
Thanks,
Steele.
0
Marin
Telerik team
answered on 01 Dec 2010, 12:33 PM
Hi Steele,

Yes, adding a hidden column that holds this value is another possible option. If you do need to have this value retrieved from the database when the grid is bound, you can either use a template column or additional column with visibility="false" that is bound to that value.

Regards,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Steele
Top achievements
Rank 1
Answers by
Marin
Telerik team
Steele
Top achievements
Rank 1
Share this question
or