gdubs
gdubs

Reputation: 2754

bind sqldatasource result to textbox c#

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>

Upvotes: 2

Views: 13549

Answers (2)

obulet
obulet

Reputation: 99

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>

Upvotes: 5

SidC
SidC

Reputation: 3203

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:)

Upvotes: 1

Related Questions