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

How can I get value from GridDropDownColumn ?

1 Answer 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pichet
Top achievements
Rank 1
Pichet asked on 21 Mar 2012, 06:53 AM

How can I get value from GridDropDownColumn ? in c# on Code behind

Could you please help ?

<telerik:RadScriptManager ID="RadScriptManager" runat="server"></telerik:RadScriptManager>
        <!-- content start -->
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadGrid ID="RadGrid1" Width="97%"
             AllowPaging="True"
             PageSize="15"
             runat="server"
             AllowSorting="True"
             OnCreateColumnEditor="RadGrid1_CreateColumnEditor"
             OnNeedDataSource="RadGrid1_NeedDataSource"
             OnDeleteCommand="RadGrid1_DeleteCommand"
             OnInsertCommand="RadGrid1_InsertCommand"
             OnItemDataBound="RadGrid1_ItemDataBound"
             AllowAutomaticDeletes="True"
             GridLines="None" Skin="WebBlue"
             AllowAutomaticInserts="True">
              <MasterTableView Width="100%" DataKeyNames="DestinationId" AutoGenerateColumns="False">
               <Columns>
 
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    <ItemStyle CssClass="MyImageButton" />
                </telerik:GridEditCommandColumn>
 
                <telerik:GridBoundColumn DataField="DestinationId" HeaderText="DestinationId" SortExpression="DestinationId"
                    UniqueName="DestinationId" ColumnEditorID="GridTextBoxColumnEditor1" ReadOnly="false" Visible="true">
                </telerik:GridBoundColumn>
                 
                <telerik:GridDropDownColumn DataField="OriginCountryCode"
                    HeaderText="Traveling From Country" ListTextField="CountryName" ListValueField="CountryCode"
                    UniqueName="OriginCountryCode" ColumnEditorID="GridDropDownColumnEditor1">
                </telerik:GridDropDownColumn>
 
                <telerik:GridDropDownColumn DataField="DestinationCountryCode"
                    HeaderText="Destination Country" ListTextField="CountryName" ListValueField="CountryCode"
                    UniqueName="DestinationCountryCode" ColumnEditorID="GridDropDownColumnEditor1">
                </telerik:GridDropDownColumn>
 
                <telerik:GridDropDownColumn DataField="PurposeId"
                    HeaderText="Purpose of Trip" ListTextField="Description" ListValueField="PurposeId"
                    UniqueName="PurposeId" ColumnEditorID="GridDropDownColumnEditor1">
                </telerik:GridDropDownColumn>
 
                <telerik:GridDateTimeColumn UniqueName="DateOfArrival" PickerType="DatePicker" HeaderText="Date of Arrival"
                            DataField="DateOfArrival"
                            <ItemStyle Width="120px" />
                        </telerik:GridDateTimeColumn>
 
                <telerik:GridDateTimeColumn UniqueName="DateOfDeparture" PickerType="DatePicker" HeaderText="Date of Departure"
                            DataField="DateOfDeparture"
                            <ItemStyle Width="120px" />
                        </telerik:GridDateTimeColumn>
 
                <telerik:GridCheckBoxColumn DataField="MultiEntry" HeaderText="Multi Entry Visa ?" SortExpression="MultiEntry"
                    UniqueName="MultiEntry">
                    <ItemStyle Width="120px" />
                </telerik:GridCheckBoxColumn>
 
                <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                    UniqueName="DeleteColumn">
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                </telerik:GridButtonColumn>
                </Columns>
 
<EditFormSettings ColumnNumber="1" CaptionDataField="DestinationId" CaptionFormatString="Destination Info {0}" >
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
</EditFormSettings>
                </MasterTableView>
            </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Mar 2012, 07:25 AM
Hello Pichet,

Try the following code snippet to access DropDownCOlumn.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
//accessing dropdowncolumn in normal mode
 if (e.Item is GridDataItem)
  {
   GridDataItem itm = (GridDataItem)e.Item;
   string comboValue = itm["DestinationCountryCode"].Text;
  }
}
//accessing dropdowncolumn in edit mode
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
   GridEditableItem itm = (GridEditableItem)e.Item;
   RadComboBox cmb = (RadComboBox)itm["DestinationCountryCode"].Controls[0];
 }
}

Thanks,
Princy.
Tags
Grid
Asked by
Pichet
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or