bind sqldatasource result to textbox c#

13,126

Solution 1

You cannot just bind textbox like that, there is no DataSourceID property on textbox. My suggestion, you may create a DataList using that DataSource and on ItemTemplate, you can do:

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind ('activitydate') %>'></asp:TextBox>

Solution 2

It looks like you've already configured your sqldatasource to utilize a stored procedure. In order to bind activitydate to a textbox, please consider using:

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind ('activitydate') 
%>'></asp:TextBox>

Hope this helps:)

Share:
13,126
gdubs
Author by

gdubs

Updated on June 04, 2022

Comments

  • gdubs
    gdubs over 1 year

    I have a SqlDataSource that returns 1 field (1 row) for an ID. I would like to get that result and display it in a TextBox. I would normally do it using a stored procedure (since the stored procedure is already created), but I was thinking SqlDataSource would be easier. Is there a way to bind that result onto my TextBox?

    <asp:SqlDataSource ID="ds1" runat="server"
        ConnectionString="<%$ ConnectionStrings:conn1%>"
        ProviderName="<%$ Connectionstrings:conn1.ProviderName %>"
        SelectCommand="sp_1"
        SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter Name="accountID" Type="Int32" />
            <asp:Parameter Name="activitydate" Type="DateTime" Direction="Output" />
        </SelectParameters>
    </asp:SqlDataSource>
    
  • gdubs
    gdubs over 12 years
    so wait, does that mean i can't bind it with anything else if i already did bind it with a sqlprocedure?
  • steph66
    steph66 over 12 years
    @gdubs: To my knowledge, you can only identify one stored procedure per SQLDataSource.