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

Populate Second Dropdownlist value on selection of Firest Dropdwon

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shailesh
Top achievements
Rank 1
Shailesh asked on 29 Feb 2012, 01:33 PM
Hi,
  I am using 2 dropdwonlist to populate product and its provider names. I am using atomatic operations fro grid. In Database my both table have  one-to-one relation. I want to get value atomatically select when i select value from first dropdownlist it should show me related values in second dropdownlist. How to do it while using atomatic grid operations.

I have code like this

<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="true"
    AllowSorting="true" EnableEmbeddedSkins="true" Skin="Sunset" AllowAutomaticInserts="true"
    PageSize="10" AllowPaging="true" PagerStyle-AlwaysVisible="true" PagerStyle-Mode="NextPrevAndNumeric"
    AllowAutomaticUpdates="true" AutoGenerateColumns="false" AllowFilteringByColumn="true"
    DataSourceID="SqlDataSource1" OnItemUpdated="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted"
    OnItemInserted="RadGrid1_ItemInserted" OnDataBound="RadGrid1_DataBound">
    <PagerStyle Mode="NextPrevAndNumeric" />
    <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="CUSTOMER_INSTRUMENT_ID"
        DataSourceID="SqlDataSource1" HorizontalAlign="NotSet" AutoGenerateColumns="False">
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                <ItemStyle CssClass="MyImageButton" />
            </telerik:GridEditCommandColumn>
            <telerik:GridDropDownColumn DataField="INSTRUMENT_ID" DataSourceID="SqlDataSource2"
                AllowFiltering="true" ShowFilterIcon="false" HeaderText="PRODUCT NAME" ListTextField="INSTRUMENT_NAME"
                ListValueField="INSTRUMENT_ID" UniqueName="INSTRUMENT_ID" ColumnEditorID="GridDropDownListColumnEditor1">
            </telerik:GridDropDownColumn>


            <telerik:GridDropDownColumn DataField="COMPANY_ID" DataSourceID="SqlDataSource3"
                HeaderText="PROVIDER COMPANY NAME" ListTextField="COMPANY_NAME" ListValueField="COMPANY_ID"
                AllowFiltering="true" ShowFilterIcon="false" UniqueName="COMPANY_ID"  ColumnEditorID="GridDropDownListColumnEditor1">
            </telerik:GridDropDownColumn>

            <telerik:GridBoundColumn DataField="OTHER_DESC" HeaderText="OTHER DESC NAME" SortExpression="OTHER_DESC"
                UniqueName="OTHER_DESC" ColumnEditorID="GridTextBoxColumnEditor1">
            </telerik:GridBoundColumn>
            <%--<telerik:GridBoundColumn DataField="INSTRUMENT_NO" HeaderText="INSTRUMENT NO" SortExpression="INSTRUMENT_NO"
                UniqueName="INSTRUMENT_NO" ColumnEditorID="GridTextBoxColumnEditor1">
            </telerik:GridBoundColumn>--%>
            <telerik:GridDateTimeColumn UniqueName="ISSUE_DATE" PickerType="DatePicker" HeaderText="DATE ISSUED"
                CurrentFilterFunction="Contains" DataField="ISSUE_DATE" FooterText="DateTimeColumn footer"
                DataFormatString="{0:MM/dd/yyyy}" EditDataFormatString="MMMM dd, yyyy hh:mm tt">
                <ItemStyle Width="120px" />
            </telerik:GridDateTimeColumn>
            <telerik:GridDateTimeColumn UniqueName="MATURITY_DATE" PickerType="DatePicker" HeaderText="MATURITY DATE"
                DataField="MATURITY_DATE" FooterText="DateTimeColumn footer" DataFormatString="{0:MM/dd/yyyy}"
                EditDataFormatString="MMMM dd, yyyy hh:mm tt">
                <ItemStyle Width="120px" />
            </telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="VALUE" HeaderText="VALUE" SortExpression="VALUE"
                CurrentFilterFunction="Contains" AllowFiltering="true" UniqueName="VALUE" ColumnEditorID="GridTextBoxColumnEditor1">
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn ConfirmText="Delete This Column?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                UniqueName="DeletColumn">
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowDblClick="RowDblClick" OnGridCreated="gridCreated" />
    </ClientSettings>
</telerik:RadGrid>.


Please help me to get through it.
How should i achive it.

Please suggest.



1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Mar 2012, 05:38 AM
Hello,

Try the following code.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditableItem && e.Item.IsInEditMode)
  {
    GridEditableItem item = (GridEditableItem)e.Item;
    RadComboBox combo = (RadComboBox)item["GridDropDownColumn"].Controls[0];
    combo.AutoPostBack = true;
   combo.SelectedIndexChanged+=new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
  }
}
void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
  //populate the second dropdown here
}

-Shinu.
Tags
Grid
Asked by
Shailesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or