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:)
Author by
gdubs
Updated on June 04, 2022Comments
-
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 over 12 yearsso wait, does that mean i can't bind it with anything else if i already did bind it with a sqlprocedure?
-
steph66 over 12 years@gdubs: To my knowledge, you can only identify one stored procedure per SQLDataSource.