...

View Full Version : Need some assistance with databinding and sqldatasource parameters



binici
12-05-2006, 08:11 PM
Hello:

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

As of now I have two sqldatasources:



<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.



<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!

binici
12-05-2006, 09:25 PM
I was doing some reading and it looks like I may need to use SqlDataSourceStatusEventArgs for add the output to a control, variable, ect?

nikkiH
12-05-2006, 11:14 PM
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/forums/t123003-modify-sqldatasource-parameters-in-code-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.

binici
12-05-2006, 11:45 PM
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/forums/t123003-modify-sqldatasource-parameters-in-code-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.

nikkiH
12-07-2006, 11:30 PM
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/library/system.web.ui.webcontrols.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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum