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

DropDownList selection for RadListBox

4 Answers 117 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 26 Jul 2011, 08:54 PM
I am needing the user to be able to select their email address in the DropDownList menu, be presented with ListBox selections and when they move the selections to the second listbox window, their UserId and Email Address are saved into the database along with their ListBox selection. I am having difficulty with the datakeyfield, datatextfield, DataValueField setup in the controls. I setup the two labels to ensure I get the proper return from the DropDown menu prior to moving the ListBox selection. I have tried all available values but seem to get the UserId in both the Email and ID columns or vice-versa. Please help.
_ JT

Hi Dimitar,
Sorry for the lack of clairity. The issue is definately with the RadListBox. The 2 labels will show the correct selected values for Email & UserID (as ID), when a selection is made in the drop-down menu. The problem is that I need to have those 2 values submitted to the database, along with the selected Name value, when the Name selection goes from RadListBox1 to RadListBox2 by the user.

Thanks,
_ JT 

<telerik:radajaxloadingpanel runat="server" id="RadAjaxLoadingPanel1" skin="Office2007" />
<telerik:radajaxpanel runat="server" id="RadAjaxPanel1" loadingpanelid="RadAjaxLoadingPanel1">
    <!-- ---------------------------------------------------------------------- -->
    <!-- DropDownList control start ----------------------------------------------- -->
    <!-- ---------------------------------------------------------------------- -->
    <asp:sqldatasource id="SqlDataSource2" connectionstring="<%$ ConnectionStrings:IPdataConnectionString %>"
        providername="System.Data.SqlClient" selectcommand="SELECT DISTINCT Email, UserId as ID FROM [aspnet_Membership]"
        runat="server"></asp:sqldatasource>
    <label for="EmailDDN">
        <asp:label id="Label2" runat="server" class="text">Select Email: </asp:label>
    </label>
    <asp:dropdownlist id="EmailDDN" runat="server" autopostback="True" datasourceid="SqlDataSource2"
        appenddatabounditems="True" datakeyfield="ID" datatextfield="Email" datavaluefield="Email" 
        onselectedindexchanged="DDN_SelectedIndexChanged">
        <asp:listitem>
         Select your email address
        </asp:listitem>
    </asp:dropdownlist>
    <br />
    <asp:label id="EmailLabel1" runat="server">Selected Email: </asp:label>
    <br />
    <asp:label id="EmailLabel2" runat="server">Selected Value: </asp:label>
    <br />
    <!-- ------------------------------------------------------------------ -->
    <!-- ---------------------------------------------------------------------- -->
    <!-- ListBox control start -------------------------------------------- -->
    <telerik:radlistbox runat="server" id="RadListBox1" skin="Office2007" datasourceid="SourceDataSource"
        allowautomaticupdates="true" datakeyfield="ID" datatextfield="Name" DataValueField="ID"
        height="200px" allowtransfer="true" transfertoid="RadListBox2" transfermode="Copy" width="230px"
        autopostbackontransfer="true" />
    <telerik:radlistbox runat="server" id="RadListBox2" datasourceid="DestinationDataSource"
        allowautomaticupdates="true" datakeyfield="ID" datatextfield="Name" DataValueField="ID"
        height="200px" allowreorder="true" autopostbackonreorder="true" allowdelete="True" width="230px"
        autopostbackondelete="true" />
    <asp:sqldatasource id="SourceDataSource" runat="server" connectionstring="<%$ ConnectionStrings:IPdataConnectionString %>"
        providername="System.Data.SqlClient" 
        deletecommand="DELETE FROM Products WHERE ID = @ID"
        insertcommand="INSERT INTO Products (Name, ID, Email) VALUES (@Name, @ID, @Email)"
        selectcommand="SELECT Name, ID FROM Products" 
        updatecommand="UPDATE Products SET Name = @Name, Email = @Email WHERE ID = @ID">
        <deleteparameters>
            <asp:parameter name="ID" type="Int32" />
        </deleteparameters>
        <insertparameters>
            <asp:parameter name="Name" type="String" />
            <asp:controlparameter name="Email" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
            <asp:controlparameter name="ID" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
        </insertparameters>
        <selectparameters>
            <asp:controlparameter name="Email" controlid="EmailDDN" propertyname="SelectedValue" type="String" />
            <asp:controlparameter name="ID" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
        </selectparameters>
        <updateparameters>
            <asp:parameter name="Name" type="String" />
            <asp:controlparameter name="Email" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
            <asp:controlparameter name="ID" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
        </updateparameters>
    </asp:sqldatasource>
    <asp:sqldatasource id="DestinationDataSource" runat="server" connectionstring="<%$ ConnectionStrings:IPdataConnectionString %>"
        providername="System.Data.SqlClient" 
        deletecommand="DELETE FROM ProductsMail WHERE ID = @ID"
        insertcommand="INSERT INTO ProductsMail (Name, Email, ID) VALUES (@Name, @Email, @ID)"
        selectcommand="SELECT Name, ID, Email FROM ProductsMail" 
        updatecommand="UPDATE ProductsMail SET Name = @Name, Email = @Email WHERE ID = @ID">
        <deleteparameters>
            <asp:parameter name="ID" type="Int32" />
        </deleteparameters>
        <insertparameters>
            <asp:parameter name="Name" type="String" />
            <asp:controlparameter name="Email" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
            <asp:controlparameter name="ID" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
        </insertparameters>
        <updateparameters>
            <asp:parameter name="Name" type="String" />
            <asp:controlparameter name="Email" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
            <asp:controlparameter name="ID" propertyname="SelectedValue" controlid="EmailDDN" type="String" />
        </updateparameters>
    </asp:sqldatasource>
</telerik:radajaxpanel>

====

 

 

protected void DDN_SelectedIndexChanged(System.Object sender, System.EventArgs e)

 

{

EmailLabel1.Text = EmailDDN.SelectedItem.ToString();

EmailLabel2.Text = EmailDDN.SelectedValue.ToString();

}



4 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 29 Jul 2011, 04:37 PM
Hi John,

I've inspected the code you have provided but I'm not sure whether the experienced problem is related to the drop-down or the RadListBox controls?

By default the DataValueField define which column's values will be bound as the value property of the listbox items, the DataTextField defines the same, but for the Text property. The DataKeyField should define which is the column containing the primary keys.

Please clarify what exactly is the problem that you are experiencing and what is the desired functionality that you are trying to implement.

Kind regards,
Dimitar Terziev
the Telerik team

Browse the vast support resources we have to jump start 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
John
Top achievements
Rank 1
answered on 29 Jul 2011, 05:04 PM
Hi Dimitar,
Sorry for the lack of clairity. The issue is definately with the RadListBox. The 2 labels will show the correct selected values for Email & UserID (as ID), when a selection is made in the drop-down menu. The problem is that I need to have those 2 values submitted to the database, along with the selected Name value, when the Name selection goes from RadListBox1 to RadListBox2 by the user.

Thanks,
_ JT 
0
Dimitar Terziev
Telerik team
answered on 03 Aug 2011, 04:42 PM
Hello John,

In order to troubleshoot this issue, please open a support ticket and send us a sample page demonstrating the issue.

Greetings,
Dimitar Terziev
the Telerik team

Browse the vast support resources we have to jump start 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
John
Top achievements
Rank 1
answered on 05 Aug 2011, 02:35 PM
Hi Dimitar,
Thanks, will do.

_ JT
Tags
ListBox
Asked by
John
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
John
Top achievements
Rank 1
Share this question
or