Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need some assistance with databinding and sqldatasource parameters

    Hello:

    I have come to a tricky part of my webproject. This maybe a bit confusing.

    As of now I have two sqldatasources:

    Code:
    <asp:SqlDataSource ID="sqlBrokersAgentsRecips" runat="server" ConnectionString="<%$ AppSettings:connectionstring %>" ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="callcenterdev..spGetBrokersAgentsForRecips">
        <SelectParameters>
            <asp:Parameter Name="OfficeId" DefaultValue="88430760" />
        </SelectParameters>
    </asp:SqlDataSource>
    
    <asp:SqlDataSource  ID="sqlMembersOfficeId" runat="server" ConnectionString="<%$ AppSettings:connectionstring %>" ProviderName="System.Data.SqlClient" SelectCommandType="Text" SelectCommand="SELECT m.Office_Number FROM rapdata..Member m WITH(NOLOCK) WHERE Member_Number = @sesBrokerId">
        <SelectParameters>
            <asp:SessionParameter SessionField="sesBrokerId" Name="sesBrokerId" />
        </SelectParameters>
    </asp:SqlDataSource>
    The sqlMembersOfficeId retrieves the office_number I need correctly, (I know because I have checked the db value and have outputted the value on a label control).

    Now the tricky part I am trying to understand is, I need the office_id to be passed for the sqlBrokersAgentsRecips (as you can see I just manually add the value for now to test). Upon doing so I will be able to bind a dropdownlist with the correct members within the office_number.

    Code:
    <asp:DropDownList ID="BrokerAgentNamesDD" runat="server" DataSourceID="sqlBrokersAgentsRecips" DataTextField="Agent_Name" DataValueField="Member_Number">
    </asp:DropDownList>
    I know in asp 3.0 you could just sub out all your stored procedures and call them anytime, but looks like its much more elaborate in .NET.

    Thanks for your help!

  • #2
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was doing some reading and it looks like I may need to use SqlDataSourceStatusEventArgs for add the output to a control, variable, ect?

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    That depends.
    Where are you getting the variable from and when?
    By when, I mean before the page loads, when a user clicks a button, or something like that.

    This might help.
    http://www.velocityreviews.com/forum...de-behind.html

    .NET is a whole 'nother animal from classic asp. Forget most of what you knew for classic asp, as it just doesn't apply to this model.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #4
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH View Post
    That depends.
    Where are you getting the variable from and when?
    By when, I mean before the page loads, when a user clicks a button, or something like that.

    This might help.
    http://www.velocityreviews.com/forum...de-behind.html

    .NET is a whole 'nother animal from classic asp. Forget most of what you knew for classic asp, as it just doesn't apply to this model.
    Oh I totally agree!

    To answer you question, I am passing the session value of sesBrokerId when the page loads. To make things clearer, I could explain a bit more thoroughly.

    When I click to view the page, the variable is collected and I send it through sqlMembersOfficeId as a parameter, I want to then be able to set or some how send the returned value of that query to the first sqlBrokersAgentsRecips, which would then populate my dropdownlist correctly and all this should happen on page_load.

    Is there a way to do this? I have tried to bind the returned value from the second query to a datalist, which I added a label field, but when I add a selectparameter it doesnt like the child control.
    Last edited by binici; 12-06-2006 at 12:06 AM.

  • #5
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Can you get the behavior you're looking for without all that, by hard-coding the ID like your first post?

    If so, you can dynamically set (and create, if you felt like it) a parameter value in Page_Load. There's a J# example here. It's pretty easy to understand and make into VB or C#.
    http://msdn2.microsoft.com/en-us/lib...parameter.aspx

    I wonder why you're using SqlDataSource for that office id query, though, if you're not data binding it to anything...I would think it would be a lot faster to just executeScalar for one value. And by faster, I mean execution time, less overhead, better for the application.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •