asp.net - handle an event in sql

do I have the session varaible formtted correctly  here?
DefaultValue="Session('rptShoereporting')"

also I need to control what parameter is sent to the sql server db...with the below code...is that correct?

===================

    <asp:SqlDataSource ID="dsItemsDetail" runat="server"  OnInserted="ObjectDataSourceStatusEventHandler" ConnectionString="<%$ ConnectionStrings:abcCompConnectionString %>"
                    SelectCommandType="StoredProcedure" SelectCommand="rptShoeReporting">
                    <SelectParameters>
                        <asp:Parameter Name="RptType" Type="Int32" DefaultValue="Session('rptshoereporting')" />
                        <asp:Parameter Name="RptSubType" Type="string" />
                        <asp:Parameter Name="Userid" Type="string" />
                    </SelectParameters>
                </asp:SqlDataSource>


-------


    Protected Overrides Sub OnInit(ByVal e As EventArgs)
        MyBase.OnInit(e)
        odsOrders.Selected += New ObjectDataSourceStatusEventHandler(odsOrders_Selected)
        odsCustomersList.Selected += New ObjectDataSourceStatusEventHandler(AddressOf odsCustomersList_Selected)
    End Sub

    Private Sub odsCustomersList_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
        'notice that this datasource returns a DataView
        lblCount1.Text = "Total Record count in the dropdownlist above= " & DirectCast(e.ReturnValue, DataView).Count.ToString()
    End Sub
LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GlobaLevelProgrammerAuthor Commented:
oops, had the wrong method in there...


    Protected Overrides Sub OnInit(ByVal e As EventArgs)
        MyBase.OnInit(e)
        odsOrders.Selected += New ObjectDataSourceStatusEventHandler(odsOrders_Selected)
        odsCustomerList.Selected += New ObjectDataSourceStatusEventHandler(AddressOf odsCustomersList_Selected)
    End Sub

    Private Sub odsCustomersList_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
        'notice that this datasource returns a DataView

        If ddlUser.Text = "ALL" Then
            Session("rptshoereporting") = "6"
        End If

        If ddlUser.Text <> "ALL" Then
            Session("rptshoereporting") = "4"
        End If


    End Sub
0
Paul MacDonaldDirector, Information SystemsCommented:
For the first question, it should be;
    DefaultValue=Session('rptShoereporting')

As to the second question, I'd think it should be:
    <asp:Parameter Name="RptType" Type="Int32" DefaultValue=Session('rptshoereporting') />.. but I'm not authoritative on that.
     

0
GlobaLevelProgrammerAuthor Commented:
I tried your way, but I get an error, the input string is not a correct format
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Paul MacDonaldDirector, Information SystemsCommented:
Hmmm.  How about:

<asp:Parameter Name='RptType' Type='Int32' DefaultValue=' & Session("rptshoereporting") & ' />
0
GlobaLevelProgrammerAuthor Commented:
that didnt work...either..
0
CodeCruiserCommented:
As I said, use a control parameter to supply the selected value from dropdownlist to the sqldatasource

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx
0
Paul MacDonaldDirector, Information SystemsCommented:
Ugh, sorry.  Try this:
<asp:Parameter Name='RptType' Type='Int32' DefaultValue='<% =Session("rptshoereporting") %>' />
0
GlobaLevelProgrammerAuthor Commented:
if I use a controlparameter ....if the dropDownlist ="all" then send the parameter "7" to the sql


its not really apart of the DLL as its not apart of the dataset ..


publkic sub page_load...
...
            ddlUser.DataSource = dv
            ddlUser.DataBind()
            ddlUser.Items.Insert(0, New ListItem("ALL", "-1"))
..
end sub


 <asp:SqlDataSource ID="dsItemsDetail" runat="server"   ConnectionString="<%$ ConnectionStrings:abccompConnectionString %>"
                    SelectCommandType="StoredProcedure" SelectCommand="rptshoeReporting">
                    <SelectParameters>
                        <asp:controlparameter name="RptType" Type="Int32" controlid="ddluser" propertyname="All" DefaultValue="7" />

                        <asp:Parameter Name="RptType" Type="Int32" DefaultValue="4"  />
                        <asp:Parameter Name="RptSubType" Type="string" />
                        <asp:Parameter Name="Userid" Type="string" />
                    </SelectParameters>
                </asp:SqlDataSource>


---

havent used the control paramter all that much..see how RptType is in there twice?
Server Error in '/' Application.
--------------------------------------------------------------------------------

DataBinding: 'System.Web.UI.WebControls.DropDownList' does not contain a property with the name 'All'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: DataBinding: 'System.Web.UI.WebControls.DropDownList' does not contain a property with the name 'All'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:

Open in new window

0
CodeCruiserCommented:
>propertyname="All"

There is no All property on drop down list. Use

propertyname="SelectedValue"
0
GlobaLevelProgrammerAuthor Commented:
okay now I get the error:
Parameter '@RptType' was supplied multiple times.
0
CodeCruiserCommented:
Do you have any other code that sets its value?
0
GlobaLevelProgrammerAuthor Commented:
yeah this in bold is also setting its value....it was pasted in above too...


 <asp:SqlDataSource ID="dsItemsDetail" runat="server"   ConnectionString="<%$ ConnectionStrings:abccompConnectionString %>"
                    SelectCommandType="StoredProcedure" SelectCommand="rptshoeReporting">
                    <SelectParameters>
                        <asp:controlparameter name="RptType" Type="Int32" controlid="ddluser" propertyname="All" DefaultValue="7" />

                        <asp:Parameter Name="RptType" Type="Int32" DefaultValue="4"  />
                        <asp:Parameter Name="RptSubType" Type="string" />
                        <asp:Parameter Name="Userid" Type="string" />
                    </SelectParameters>
                </asp:SqlDataSource>
0
GlobaLevelProgrammerAuthor Commented:
so I get a dropdownlist on page load:

All
John Smith
Eddie James
Mary Connor

if they choose 'All' then the value of the parameter RptTYpe needs to be changed to "7"
If they choose anything else than 'All', the value of the paramter RptType needs to be "4"
0
CodeCruiserCommented:
Your dropdown needs to be populated with values. Then you only use ControlParameter not both Parameter and Controlparameter. The value will then  be automatically passed to sqldatasource.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.