将sqldatasource结果绑定到文本框c#

将sqldatasource结果绑定到文本框c#,c#,asp.net,data-binding,sqldatasource,C#,Asp.net,Data Binding,Sqldatasource,我有一个SqlDataSource,它为ID返回1个字段(1行)。我希望得到该结果并将其显示在文本框中。我通常会使用存储过程(因为存储过程已经创建),但我认为SqlDataSource会更容易。有没有办法将结果绑定到我的文本框中 <asp:SqlDataSource ID="ds1" runat="server" ConnectionString="<%$ ConnectionStrings:conn1%>" ProviderName="<%$ Conne

我有一个SqlDataSource,它为ID返回1个字段(1行)。我希望得到该结果并将其显示在文本框中。我通常会使用存储过程(因为存储过程已经创建),但我认为SqlDataSource会更容易。有没有办法将结果绑定到我的文本框中

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

看起来您已经将sqldatasource配置为使用存储过程。若要将活动日期绑定到文本框,请考虑使用:

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


希望这有帮助:)

您不能像那样绑定textbox,textbox上没有DataSourceID属性。 我的建议是,您可以使用该数据源创建数据列表,在ItemTemplate上,您可以执行以下操作:

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


等等,这是否意味着如果我已经用sqlprocedure绑定了它,我就不能用其他任何东西绑定它?@gdubs:据我所知,每个SQLDataSource只能标识一个存储过程。