?
Solved

asp.net - handle an event in sql

Posted on 2011-10-17
14
Medium Priority
?
260 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:GlobaLevel
  • 7
  • 4
  • 3
14 Comments
 
LVL 10

Author Comment

by:GlobaLevel
ID: 36980168
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
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36980198
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
 
LVL 10

Author Comment

by:GlobaLevel
ID: 36981526
I tried your way, but I get an error, the input string is not a correct format
0
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.

 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36982111
Hmmm.  How about:

<asp:Parameter Name='RptType' Type='Int32' DefaultValue=' & Session("rptshoereporting") & ' />
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 36982757
that didnt work...either..
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36984975
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
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36986021
Ugh, sorry.  Try this:
<asp:Parameter Name='RptType' Type='Int32' DefaultValue='<% =Session("rptshoereporting") %>' />
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 36994362
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36995169
>propertyname="All"

There is no All property on drop down list. Use

propertyname="SelectedValue"
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 36995467
okay now I get the error:
Parameter '@RptType' was supplied multiple times.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36995496
Do you have any other code that sets its value?
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 36995529
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
 
LVL 10

Author Comment

by:GlobaLevel
ID: 36995542
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 37002636
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

839 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