Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pass multiple select list value to objectdatasource parameter

Posted on 2014-09-15
1
Medium Priority
?
661 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

660 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