943,935 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 15485
  • ASP.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 22nd, 2004
0

Help with Databinding

Expand Post »
I am trying to databind one entry retrieved from a SQL statement.

All I want to do is databind in the code behind page.

For some reason I have lost my brain and cannot figure out how to do it....
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Horizon is offline Offline
2 posts
since Dec 2004
Dec 22nd, 2004
0

Re: Help with Databinding

Databind WHAT to WHAT? You have your data in SQL, you get it out and it's now inside, what? A DataReader? DataTable?

You want to bind this data to which ASP.NET Server control?
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Dec 22nd, 2004
0

Re: Help with Databinding

Sorry I should have made myself clearer.

I was trying to databind to a label, and just found an easier way. Through the use of the Command Object.

I was losing my train of thought and went on to post the question but didnt realize I left out the main reason.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Horizon is offline Offline
2 posts
since Dec 2004
Dec 22nd, 2004
0

Re: Help with Databinding

Which Command object? For SQL Commands?
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Dec 22nd, 2004
0

Re: Help with Databinding

Yes, sorry to say but you are not being very clear in what you are wanting to do.

Have you successfully connected to the SQL Server DB?

You can use a Container to the specific Value you want to associate with the LABEL Object.

Below is a sample to this code:
<asp:Label id="label1" runat="server"
  Text='<%# Container.DataItem("CustomerName") %>




Hope this helps!

Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Jun 27th, 2005
0

Re: Help with Databinding

So, would you use it like this:

ASP.NET Syntax (Toggle Plain Text)
  1. <tr><td colspan="2"><hr color="#F53167" width="100%" size="3"></td></tr>
  2. <tr><td colspan="2">
  3. <form id="form1" runat="server">
  4. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tcmConnectionString1 %>" SelectCommand="SELECT * FROM [prod]">
  5. </asp:SqlDataSource>
  6. <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:tcmConnectionString1 %>" SelectCommand="SELECT [prod_description] FROM [prod] WHERE ([ID] = @ID)">
  7. <SelectParameters>
  8. <asp:ControlParameter ControlID="DropDownList1" Name="ID" PropertyName="SelectedValue"
  9. Type="Int64" />
  10. </SelectParameters>
  11. </asp:SqlDataSource>
  12. <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
  13. DataTextField="prod_name" DataValueField="ID">
  14. </asp:DropDownList><br />
  15. &nbsp;<asp:Label ID="Label1" runat="server" Text='<%# SQLDataSource2.DataItem("prod_description") %>'></asp:Label>
  16. </form></td></tr>
  17. </table>

I am pretty sure I am way off.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jturlington is offline Offline
4 posts
since Jun 2005
Jun 27th, 2005
0

Re: Help with Databinding

Please wrap your code in code tags. Please start a new thread, rather than posting your question as a reply to a resolved thread.

With ASP.NET, it's best practice to separate your pages into an "HTML" template, and a code-behind file.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Jun 27th, 2005
0

Re: Help with Databinding

editted post
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jturlington is offline Offline
4 posts
since Jun 2005
Jun 27th, 2005
0

Re: Help with Databinding

Edited...ok. But what are you asking still?

Quote originally posted by jturlington ...
editted post
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Jun 27th, 2005
0

Re: Help with Databinding

to have the dropdownlist change what the text of the label is.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jturlington is offline Offline
4 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Use of Image control on Web Page
Next Thread in ASP.NET Forum Timeline: Type ' ' Not Defined





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC