Solved

Pass multiple select list value to objectdatasource parameter

Posted on 2014-09-15
1
506 Views
Last Modified: 2014-10-14
Using an ObjectDataSource to get a listbox in multiple select mode.  I can grab the value as a single value but the value of the parameter doesn’t seem to pass when set as multiple.  Would really appreciate an example of how to make this work if you know.  

Asp.net
<asp:ListBox ID="lstAction" runat="server" Rows="3" SelectionMode="Multiple"></asp:ListBox>

<asp:ObjectDataSource ID="odsSalesSC" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="RapidFire.RFTableAdapters.USP_TOTAL_ORDERCALLSTableAdapter" OnSelecting="odsSalesSC_Selecting" OnSelected="odsSalesSC_Selected">
            <SelectParameters>
                <asp:ControlParameter ControlID="lstAction" Name="action" PropertyName="SelectedValue" Type="String" ConvertEmptyStringToNull="true" />                
            </SelectParameters>
        </asp:ObjectDataSource>

Open in new window


Code behind

List<string> lAction = new List<string>();
        lAction.add("1");
        lAction.add("2");
        lAction.add("3");
        listAction.DataSource = lAction;

protected void odsSalesSC_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            String strAction = String.Empty;
            foreach (ListItem liAction in lstAction.Items)
            {
                if (liAction.Selected)
                {
                    strAction += "'" + liAction.Value + "',";
                }
            }
            strAction = strAction.Substring(0, strAction.Length - 1);
            e.InputParameters["action"] = strAction;
           //value when I debug is '1','2','3'
            }
}

Open in new window




ALTER PROCEDURE [dbo].[USP_TOTAL_ORDERCALLS] 
      -- Add the parameters for the stored procedure here
@action as varchar(50) = null,
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

if (@action is null)
      begin
            select * from
            VIEW_TOTAL_ORDERSCALLS
            where
            SalesAction = coalesce(@action, SalesAction)
      end
else
      begin
            select * from 
            VIEW_TOTAL_ORDERSCALLS
            where
            SalesAction in (@action)
            
end

Open in new window

0
Comment
Question by:Scarlett72
1 Comment
 
LVL 8

Accepted Solution

by:
johny_bravo1 earned 500 total points
ID: 40365748
Try adding
odsSalesSC.SelectParameters.Clear();
odsSalesSCSelectParameters.Add("YourParamName",paramValues);
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now