Solved

Pass multiple select list value to objectdatasource parameter

Posted on 2014-09-15
1
611 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 500 total points
ID: 40365748
Try adding
odsSalesSC.SelectParameters.Clear();
odsSalesSCSelectParameters.Add("YourParamName",paramValues);
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

635 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