Solved

Pass multiple select list value to objectdatasource parameter

Posted on 2014-09-15
1
567 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running powershell scripts from ASP.NET 6 59
ASP.NET - Why is accordion not working? 3 50
C# Windows app updating JSON file error. 9 39
asp.net web app 3 25
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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