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

Drop Down Bind after re populating

2 Answers 60 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Llewellen
Top achievements
Rank 1
Llewellen asked on 19 Sep 2016, 03:33 PM

Hi All,

I'm using the selectedindexchanged of one of my Drop down lists to populate another ddl.

It's populating the ddl with with the data i want. However when i want to use the newly populated ddl value/text for a insert/update. It only updates/inserts as a blank value.

i know this has something to do with my Data Biding, but i can't seem to get the ddl to bind.

 

Code Used to populate the ddl:

    protected void RadDropDownList3_SelectedIndexChanged(object sender, DropDownListEventArgs e)
    {
        RadDropDownList DropDownList3 = ((RadDropDownList)((RadDropDownList)sender).Parent.FindControl("RadDropDownList3"));
        RadDropDownList DropDownList2 = ((RadDropDownList)((RadDropDownList)sender).Parent.FindControl("RadDropDownList2"));


        DropDownList2.DataSourceID = null;
        DropDownList2.DataSource = null;
        DropDownList2.Items.Clear();

        string prinparam = DropDownList3.SelectedText;
        string strqry = string.Format(@"select distinct locationfullname from D_Location where DivisionName = '" + prinparam + "'  ORDER BY 1 ;", prinparam);
        DataTable dt = new DataTable();
        using (strcon)
        {
            var command = new SqlCommand(strqry, strcon);

            SqlDataAdapter da = new SqlDataAdapter(strqry, strcon);
            strcon.Open();
            DataSet ds = new DataSet();

            da.Fill(dt);
            DropDownList2.Items.Clear();

            foreach (DataRow dr in dt.Rows)
            {
                DropDownList2.Items.Add(dr[0].ToString());

            }
        }
        DropDownList2.DataBind();
        DropDownList2.SelectedValue = DropDownList2.SelectedText;

    }

 

 

2 Answers, 1 is accepted

Sort by
0
Llewellen
Top achievements
Rank 1
answered on 20 Sep 2016, 06:23 AM

The RadDropDownList is in an editform.

 

                <EditFormSettings EditFormType="Template" >
                <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
                    <FormTemplate>
                        <table id="Table2" cellspacing="2" cellpadding="1" width="50%" border="0" rules="none"
                            style="border-collapse: collapse;">
                            <tr class="EditFormHeader">
                                <td colspan="2">
                                    <b>Employee Details</b>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <table id="Table3" width="450px" border="0" class="module">
                                        <tr>
                                            <td>Username:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="TextBox2" Text='<%# Bind("NTUser") %>' runat="server" TabIndex="1" Width ="223px">
                                                </asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Group:
                                            </td>
                                            <td>
                                                <asp:TextBox ID="TextBox3"   runat="server" TabIndex="2" Width ="223px" Enabled ="false" Text="Unitrans Automotive">
                                                </asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Division:
                                            </td>
                                            <td>
                                                <telerik:RadDropDownList ID="RadDropDownList3"  runat="server" DataSourceID="SqlDataSource3" DataValueField="Division" DataTextField="Division" SelectedValue='<%# Bind("Division") %>'  Width ="250px"   AutoPostBack="true" OnSelectedIndexChanged="RadDropDownList3_SelectedIndexChanged" ></telerik:RadDropDownList>
                                            </td>
                                        </tr>


                                        <tr>
                                            <td>Location:
                                            </td>
                                            <td>
                                                <telerik:RadDropDownList ID="RadDropDownList2"  runat="server" DataSourceID="SqlDataSource2" DataValueField="Location" DataTextField="Location" SelectedValue='<%# Bind("Location") %>'  Width ="250px"   AutoPostBack="true" ></telerik:RadDropDownList>

                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Autorun:
                                            </td>
                                            <td>
                                                <telerik:RadDropDownList ID="RadDropDownList1"  runat="server" DataSourceID="SqlDataSource4" DataValueField="Value" DataTextField="Text" SelectedValue='<%# Bind("Autorun") %>'  Width ="250px"></telerik:RadDropDownList>
                                            </td>
                                        </tr>

                                    </table>
                                </td>                                
                            </tr>
                            <tr>
                                <td colspan="2"></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr>
                             <tr>
                                <td align="left" colspan="2">
                                    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
                                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                        CommandName="Cancel"></asp:Button>
                                </td>
                            </tr>
                            </tr>
                        </table>
                    </FormTemplate>
                </EditFormSettings>

0
Eyup
Telerik team
answered on 22 Sep 2016, 07:27 AM
Hi Llewellen,

For achieving cascading comboboxes functionality in RadGrid edit mode, I suggest that you check the samples provided in the following post:
http://www.telerik.com/forums/radcombobox-cascading-inside-radgrid#GxsIQqyyPkqj1Za-mNbalg


As for accessing the combo on server-side you can use the FindControl method:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

For client-side, you can use the $telerik.findControl and findElement methods suggested in the following post:
http://www.telerik.com/forums/how-to-change-and-get-value-from-a-dropdownlist-in-a-radgrid-column#jIjRiaOYhkucLZ82pztwow

I hope this will prove helpful.


Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
DropDownList
Asked by
Llewellen
Top achievements
Rank 1
Answers by
Llewellen
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or