Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

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
Avatar of GlobaLevel
GlobaLevel
Flag of United States of America image

ASKER

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
Avatar of Paul MacDonald
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.
     

I tried your way, but I get an error, the input string is not a correct format
Hmmm.  How about:

<asp:Parameter Name='RptType' Type='Int32' DefaultValue=' & Session("rptshoereporting") & ' />
that didnt work...either..
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
Ugh, sorry.  Try this:
<asp:Parameter Name='RptType' Type='Int32' DefaultValue='<% =Session("rptshoereporting") %>' />
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

>propertyname="All"

There is no All property on drop down list. Use

propertyname="SelectedValue"
okay now I get the error:
Parameter '@RptType' was supplied multiple times.
Do you have any other code that sets its value?
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>
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"
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial