Using returned value from SqlDataSource1

I, a newbie, can't seem to figure this out or find the answer on forums. Any help you could offer me is appreciated. VS2005, C#, Web forms.

What I'm doing is writing the login name and password to Profile.Login & Profile.Password from the text boxes on a login screen only if there is such a combo. I also want to write the person's UserID but can't get it out of the SqlDataSource1.

I have an SqlDataSource1 that returns a distinct integer value (134 for example). I can display this value in a grid view, details view, and so on by linking the datasource to the grid view. The query works but...

I want to be able to write the returned value to <%= Profile.UserID %> for use throughout the web app but can't figure out how to get the value being returned from SqlDataSource1 or from the gridview, detailsview.

Data Source Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MY-DB-WORKS %>"
OnSelecting="SqlDataSource1_Selecting1"
SelectCommand="SELECT DISTINCT [User].UserId FROM Application INNER JOIN [User] ON Application.DealerId = [User].UserId WHERE ([User].LoginId = @login) AND ([User].LoginPwd = @password) ">

<SelectParameters>

<asp:ProfileParameter Name="login" PropertyName="login" />
<asp:ProfileParameter Name="password" PropertyName="password" />
</SelectParameters>

</asp:SqlDataSource>


Can anyone tip me off as to how I can make the Profile.UserID value equal what SqlDataSource1 is returning

Thank you for your help!
-Corby-


Answer this question

Using returned value from SqlDataSource1

  • AshikWani

    <%=Profile.UserId%> just outputs the value as html.

    what you want is

    <%Profile.UserId=TextBox1.Text;%>



  • shamim

    I read the article but it didn't really click for me.

    The SqlDataSource1 returns a value, 134. How can I get the value into a TextBox If I can get it out of the SqlDataSource1 or out of the GridView or DetailsView tied to the SqlDataSource1, I should be able to easily set:

    <%= Profile.UserId %> = TextBox1.Text

    That would fix my problem but I can't get the value into the TextBox1...

    There has to be something incredibly simple that I'm overlooking...my web searching and book reading is getting me nowhere on this. Looking forward to some more insight from anyone willing to point me in the right direction.

    Thanks again everyone!
    -Corby-



  • Johnathon

    Thanks for the response. What I have is a gridview and details view that are bound to the SqlDataSource1. They are both showing 134 as the distinct output for a given username password combo. I can't figure out how to get that 134 value into the textbox you suggested or to set the <%= Profile.UserId %> equal to the 134 value.

  • Jay B. [Mobius Labs]

    I think you need to bind to the output of the select then reference the value from the bound item, something like so:

    <asp:textbox
    id="ProfileValue"
    runat="server"
    datasourceid="SqlDataSource1"
    datatextfield="UserId">
    </asp:textbox>

    This is the whole point of the SQLDataSource to provide data to data bound controls.



  • naama

    Oh, so you have the data bound to a gridview but you want to extract the data from the gridview and inline the value.

    I found this, it might help ->

    http://www.ftponline.com/vsm/2006_01/magazine/columns/aspnet/

    Control the Data
    Out of all the columns in the Customers GridView, you might wonder how the Orders SqlDataSource selects the correct field to control the Orders GridView. It's not magic: The Orders GridView uses the value in the Customers GridView's SelectedValue property. When a GridView is bound to a SqlDataSource, the GridView's SelectedValue property defaults to the table's primary key. For the Customers table, the SelectedValue defaults to the CustomerId that you need in order to retrieve related Orders records. The process is more obvious if you use an ObjectDataSource to retrieve the data for your GridView, because the SelectedValue property doesn't default to any value. Instead, you must use the DataKeyNames property to specify the property to be returned by SelectedValue (see Figure 2).

    So you could try reading the SelectedValue of the gridview.



  • PatMc

    I couldn't get the value into TextBox1.Text from the SqlDataSource...

  • Using returned value from SqlDataSource1