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>
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>
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:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.