Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pass multiple select list value to objectdatasource parameter

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Loops Section Overview
Suggested Courses

916 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