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

ReBind ComboBox from DataGrid when in Insert Mode

2 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 24 Aug 2012, 01:33 PM
Hi, I have a RadGrid bringing data back from the database. When I add a new Item I have several ComboBoxes. The first is populated when the EditForm opens. I next want to bind the next ComboBox with the selected value of the first ComboBox when the selected value changes. How do I do it?

I have another 3 ComboBoxes (not shown yet) that will continue in the same way as each selected value changes.

    <telerik:RadGrid DataSourceID="dsActionList" ID="rdgActions" runat="server" CellSpacing="0"
        GridLines="None" AllowPaging="True" PageSize="10" EnableHeaderContextMenu="True"
        AutoGenerateColumns="False" ShowStatusBar="True">
        <ItemStyle CssClass="ItemStyle" />
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <ClientSettings EnableRowHoverStyle="True">
        </ClientSettings>
        <AlternatingItemStyle CssClass="AlternatingItemStyle" />
        <MasterTableView GridLines="None" CellSpacing="0" runat="server" DataKeyNames="PlanTestActionID"
            CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Action">
            <Columns>
                <telerik:GridTemplateColumn UniqueName="ViewEdit">
                    <ItemTemplate>
                        <asp:LinkButton Text='<%# Bind("ViewEditText") %>' runat="server" ID="btnViewEdit"
                            CommandName="Edit" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn HeaderText="Business Area" UniqueName="BusinessArea" DataField="BusinessAreaDesc">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Plan Description" UniqueName="PlanDescription"
                    DataField="PlanDescription">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Actual Date" DataFormatString="{0:dd MMM yyyy}"
                    UniqueName="ActualDate" DataField="ActualDate">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Action Title" UniqueName="ActionTitle" DataField="ActionTitle">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Target Date" DataFormatString="{0:dd MMM yyyy}"
                    UniqueName="TargetDate" DataField="TargetDate">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Action User" UniqueName="ActionUser" DataField="ActionUser">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Originator" UniqueName="Originator" DataField="Originator">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Completed Date" DataFormatString="{0:dd MMM yyyy}"
                    UniqueName="CompletedDate" DataField="CompletedTime">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Approved Date" DataFormatString="{0:dd MMM yyyy}"
                    UniqueName="ApprovedDate" DataField="ApprovedTime">
                </telerik:GridBoundColumn>
                <%--Hide the next 3 checkboxes and Date but give them a default insert value--%>
                <telerik:GridBoundColumn HeaderText="Cancelled Date" DataFormatString="{0:dd MMM yyyy}"
                    UniqueName="CancelledDate" DataField="CancelledDate" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridCheckBoxColumn DefaultInsertValue="false" DataField="Cancelled" DataType="System.Boolean"
                    UniqueName="hCancelled" Visible="False">
                </telerik:GridCheckBoxColumn>
                <telerik:GridCheckBoxColumn DefaultInsertValue="false" DataField="Completed" DataType="System.Boolean"
                    UniqueName="hCompleted" Visible="False">
                </telerik:GridCheckBoxColumn>
                <telerik:GridCheckBoxColumn DefaultInsertValue="false" DataField="Approved" DataType="System.Boolean"
                    UniqueName="hApproved" Visible="False">
                </telerik:GridCheckBoxColumn>
            </Columns>
            <EditFormSettings EditFormType="Template" PopUpSettings-Modal="True">
                <FormStyle BackColor="#E0ECFE"></FormStyle>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
                <FormTemplate>
                    <asp:HiddenField ID="hdnPlanTestActionID" runat="server" Value='<%# Bind("PlanTestActionID") %>' />
                    <asp:HiddenField ID="ViewEdit" runat="server" Value='<%# Bind("ViewEdit") %>' />
                   
                    <table>
                        <tr runat="server" id="trOriginatorDetails">
                            <td>
                                <asp:Label ID="Label34" runat="server" Text="Created By:"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="lblOriginatorUserID" runat="server" Text='<%# Bind("Originator") %>'></asp:Label>
                            </td>
                            <td width="50px">
                            </td>
                            <td>
                                <asp:Label ID="Label50" runat="server" Text="Create Time:"></asp:Label>
                            </td>
                            <td>
                                <asp:Label ID="lblCreateTime" runat="server" Text='<%# Bind("CreateTime", "{0:dd MMM yyyy}") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr runat="server" id="trDropDowns">
                            <td>
                                <asp:Label ID="Label2" runat="server" Text="Select Business Area:"></asp:Label><br />
                                <asp:Label ID="Label3" runat="server" Text="Select Business Component:"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadComboBox ID="ddlBusinessArea" runat="server" DataSourceID="dsBusinessAreaList"
                                    DataTextField="BusinessAreaDesc" DataValueField="BusinessAreaID" AppendDataBoundItems="True"
                                    AutoPostBack="True">
                                    <Items>
                                        <telerik:RadComboBoxItem Text="" Value="0" />
                                    </Items>
                                </telerik:RadComboBox>
                                <br />
                                <telerik:RadComboBox ID="ddlBusinessComponent" runat="server" DataSourceID="dsBusinessComponentList"
                                    DataTextField="ProcessDesc" DataValueField="ProcessID" AppendDataBoundItems="True"
                                    AutoPostBack="True">
                                    <Items>
                                        <telerik:RadComboBoxItem Text="" Value="0" />
                                    </Items>
                                </telerik:RadComboBox>
                            </td>
                        </tr>
                        .
                        .
                        .
                        <tr>
                            <td height="50">
                            </td>
                            <td>
                                <asp:LinkButton ID="btnUpdate" Text='<%# Iif (TypeOf Container is GridEditFormInsertItem, "Insert", "Update") %>'
                                    runat="server" CommandName='<%# Iif (TypeOf Container is GridEditFormInsertItem, "PerformInsert", "Update") %>'></asp:LinkButton>&nbsp;
                                <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                    CommandName="Cancel"></asp:LinkButton>
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView><HeaderStyle Font-Bold="True" />
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Outlook">
        </HeaderContextMenu>
    </telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Aug 2012, 05:39 PM
Hello,

Please check below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"
           OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true" AllowFilteringByColumn="true"
           EnableLinqExpressions="false">
           <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" EditMode="EditForms">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
               <EditFormSettings EditFormType="Template">
                   <FormTemplate>
                       <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1"
                           DataTextField="Name" DataValueField="ID" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
                       </telerik:RadComboBox>
                       <br />
                       <telerik:RadComboBox ID="RadComboBox2" runat="server" DataSourceID="SqlDataSource2"
                           DataTextField="Name" DataValueField="ID"></telerik:RadComboBox>
                   </FormTemplate>
               </EditFormSettings>
           </MasterTableView>
       </telerik:RadGrid>
       <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikTestDataBaseConnectionString %>"
           SelectCommand="SELECT [ID], [Name] FROM [TelerikTable1]"></asp:SqlDataSource>
       <asp:SqlDataSource ID="SqlDataSource2" runat="server"
           ConnectionString="<%$ ConnectionStrings:TelerikTestDataBaseConnectionString %>"
           SelectCommand="SELECT [Name], [ID] FROM [TelerikTable1] WHERE ([Name] = @Name)">
           <SelectParameters>
               <asp:SessionParameter DefaultValue="FirstCombo" Name="Name"
                   SessionField="FirstCombo" Type="String" />
           </SelectParameters>
       </asp:SqlDataSource>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           dynamic data = new[] {
             new { ID = 1, Name ="aaa"},
             new { ID = 2, Name = "bbb"},
             new { ID = 3, Name = "ccc"},
             new { ID = 4, Name = "ddd"},
              new { ID = 5, Name ="eee"}
           };
           RadGrid1.DataSource = data;
       }
 
       protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
            
       }
 
       protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
       {
           RadComboBox RadComboBox1 = sender as RadComboBox;
           if (RadComboBox1.SelectedIndex >= 0)
           {
               GridEditFormItem item = RadComboBox1.NamingContainer as GridEditFormItem;
               Session["FirstCombo"] = RadComboBox1.SelectedItem.Text;
               RadComboBox RadComboBox2 = item.FindControl("RadComboBox2") as RadComboBox;
               RadComboBox2.DataBind();
           }
       }



Thanks,
Jayesh Goyani
0
Tom
Top achievements
Rank 1
answered on 28 Aug 2012, 09:50 AM
Thanks Jayesh that now works for what I need.
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Tom
Top achievements
Rank 1
Share this question
or