Capturing ID on listbox to save not working...

1 posts, 0 answers
  1. Marc
    Marc avatar
    1 posts
    Member since:
    Nov 2009

    Posted 16 Jan 2011 Link to this post

    I asked this question on an old post that I do not know if it is still being monitored so I created a new thread...

    I have created the two listboxes (like in example:"ListBox / Database Update") and couldn't get them to save to the DB on transfer because it was not capturing the ID. I had to change the parameter to grab the .SelectedValue of the Outgoing list box in order to get the items to insert into the db. Problem is when I do that and I choose the "move all" button it inserts the same value several times. I'll include the code for both examples. Just so you understand I have the listbox on the left (lstLoggedInUserAccess) pulling in all of the Stores that the Logged In user has access to. There is a combo box (cboUserDealerAcces) that the user selects a list of other users. The Logged In user then will give access to the selected user (of the cboUserDealerAcces combo box) by copying the stores from the left List to the Right list (lstSelectedUserAccess).

    This code is what I have resorted to in order to get it to save to the database... but again, when I select the move all button it (understandably) inserts the same store several times because i have only captured one DealerID. I understand this but in this scenario would like to disable the 'move all' buttons. OR, The best option would be to get the lists working correctly where I could select several from the left and move them all to the right but until I'm able to capture the "DealerID" this is not an option.

    <telerik:RadComboBox ID="cboUserDealerAccess" runat="server"
        DataValueField="UserInfoID" /> 
    <asp:SqlDataSource runat="server" ID="SqlDataSource6" ConnectionString="<%$ ConnectionStrings:FT_Data %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT [LastName], [UserInfoID] FROM [UserInfo] ORDER By LastName" />   


    <telerik:RadListBox runat="server" ID="lstLoggedInUserAccess" Height="200px" Width="230px"
        AllowTransfer="true" TransferToID="lstSelectedUserAccess" TransferMode="Copy" SelectionMode="Single" DataSourceID="SqlDataSource5" DataTextField="DealerName" DataKeyField="DealerID" DataValueField="DealerID" AutoPostBackOnTransfer="true"/>


    <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:FT_Data %>" ProviderName="System.Data.SqlClient"
    SelectCommand="SELECT [DealerID], [DealerName] FROM [Dealer] ORDER By DealerName" OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues" />  


    <telerik:RadListBox runat="server" ID="lstSelectedUserAccess" Height="200px" Width="200px"
    SelectionMode="Single" DataSourceID="SqlDataSource7" DataKeyField="DealerID" DataTextField="DealerName" DataValueField="DealerID" AllowAutomaticUpdates="true" AllowReorder="false" AllowDelete="True" 
    AutoPostBackOnDelete="true" AllowTransfer="false"/> 


    <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:FT_Data %>" ProviderName="System.Data.SqlClient" 
    SelectCommand="SELECT [Dealer].[DealerID], [Dealer].[DealerName] FROM [UserDealer] INNER JOIN [Dealer] ON [UserDealer].[DealerId] = [Dealer].[DealerID] WHERE ([UserDealer].[UserInfoId] = @UserInfoID)"
    InsertCommand="INSERT INTO [UserDealer] ([UserInfoID], [DealerID]) VALUES (@UserInfoID, @DealerID)" 
    DeleteCommand="DELETE FROM [UserDealer] WHERE (UserInfoId = @UserInfoID and DealerId = @DealerID)" 
    OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues" >  



    <asp:ControlParameter Name="DealerID" Type="Int32" ControlID="lstSelectedUserAccess" PropertyName="SelectedValue" />      <asp:ControlParameter Name="UserInfoID" DbType="Int32" ControlID="cboUserDealerAccess" PropertyName="SelectedValue"/> 


    <asp:ControlParameter Name="DealerID" Type="Int32" ControlID="lstLoggedInUserAccess" PropertyName="SelectedValue" />
    <asp:ControlParameter Name="UserInfoID" DbType="Int32" ControlID="cboUserDealerAccess" PropertyName="SelectedValue"/>


    <asp:ControlParameter Name="UserInfoID" DbType="Int32" ControlID="cboUserDealerAccess" PropertyName="SelectedValue"/>




    When I change the INSERT parameter to this (see below) then it comes back empty and gives an error "Cannot Insert a Null..."

    <asp:Parameter Name="DealerID" Type="Int32"/>

Back to Top