Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Newbie Q: retrieving just one variable

    Hi,

    I'm an old asp coder but am new to both asp.net and Visual Web Designer.

    Before, when I needed just one value from a table, I used to write <%=a_name%> but what should I do now? All the tutorials I've been looking through have been geared towards the new (admittedly cool) features of the gridviews etc., so this basic feature has always been omitted).

    Lets say I have a ... (it's an sql datasource, right?) with the following SELECT statement:

    SELECT phone_no, email

    FROM user_data

    WHERE userID = 582

    and I want to insert the phone_no in one part of the page and the email address in another part of the page. I guess I shouldn't use a gridview or the like and I can't understand why there isn't a dedicated control in the "data" collection of the tool box. A neat way of achieveing this would be to be able to browse for the data in the properties pane of, say, a label. But, and to sum up:

    1. What is the proper way of achieveing this, code-wise?

    2. How do I do it in VWD (I suppose there is some kind of drag'n'drop available)?

    *

    I believe there MUST be some kind of drag'n'drop or so for attaching a chunk of data - say, a data row's email field - to a label, text field, regular html text, or whatever.

    Please help me out (before I return to Asp ;-) ). If someone could just give me a few lines of step-by-step instructions like this:

    "1. Drag a SqlDataSource to the Design View. Set its properites to the connection string and set its Sql statement as you'd like it.

    2. Drag a ... to the Design View and set its properties to ... .

    3. Drag a Label to the Design View and set its ... to ..."

    I notice a lot of people are struggling with this issue but I haven't seen any "cook-book-ish" replies so far (possibly because Asp.Net 2.0 and VWD are so new). In other words, easy to follow step-by-step instructions would most certainly be appreciated by a lot of users. (And yes, I know there are many complex ways of doing this but I just need one standard, straight-forward solution.)

    Many thanks in advance,

    Petter

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Asp.net controls do have data properties in the properties view. You can databind your values to your textbox or label or whichever. Each field in your datasource will appear in the drop down list in the properties view. But, I don't like databinding so much. I find it much easier to have other methods to handle this. Which language are you using? (VB, C#)?

    I will write up an example for you once the language is clarified.

    Good luck;

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    Why do you want a "drag and drop" solution? Does this mean not writing any code?

    If you are not adverse to writing code you can access data similarly to classic asp with a DataReader object (for example SqlDataReader for a MSSQL db) to just get certain one hit strings out or whatever.

  • #4
    Regular Coder Freon22's Avatar
    Join Date
    May 2005
    Location
    USA
    Posts
    287
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Hi, All
    I am bumping this because like the starter of this thread, I am also moving from the old vbscript to vb.net 2.0.

    I have been searching and searching through google and a few others on how to databind labels. I can say there is very little out there on this subject, so far the closest I have gotten to an answer is

    label1.text=datatable.rows(rownumber).item(columnname).tostring

    I just found this today. Its a start and I will start trying to make this work. But any help for a newbie would be great.

    Thanks

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by Freon22
    Hi, All
    I am bumping this because like the starter of this thread, I am also moving from the old vbscript to vb.net 2.0.

    I have been searching and searching through google and a few others on how to databind labels. I can say there is very little out there on this subject, so far the closest I have gotten to an answer is

    label1.text=datatable.rows(rownumber).item(columnname).tostring

    I just found this today. Its a start and I will start trying to make this work. But any help for a newbie would be great.

    Thanks
    Did you get this to work?

  • #6
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Brandoe85
    Asp.net controls do have data properties in the properties view. You can databind your values to your textbox or label or whichever. Each field in your datasource will appear in the drop down list in the properties view. But, I don't like databinding so much. I find it much easier to have other methods to handle this. Which language are you using? (VB, C#)?

    I will write up an example for you once the language is clarified.

    Good luck;
    Hi,

    Thanks a lot for the many replies. I thought I would get an email sent to me after I received replies, but no, and to make things worse, I couldn't find my way back but actually found this very post in Google(!); hence my late answer.

    I'm using VB to answer your question. I have now been using VWD and Asp.Net for several months and I understand much more (or so I think). I'm now able to do rather elaborate things, but all is accomplished without any ADO coding. So actually the question remains unanswered. :-( BTW, In the properties pane I can't find any drop down list for binding either the label to the SQLDataSource or the other way around.

    I'm eager (and I noticed another user is eager too!) to hear from anyone of you, and this time, I've added this thread to my Favourites folder and checked the email subscription. :-)

    All the best

    Petter
    Last edited by Petter; 05-03-2006 at 03:42 PM.

  • #7
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    Well you wouldnt be using ADO anyway afaik just use the System.Data.* packages to connect to your db (for example System.Data.SqlClient for mssql) There are scalar readers which return one value etc so you could use that I suppose, for multiple values its probably best to use a normal reader, pump it into a DataTable or whatever and read off that as suggested before, or put it into a couple of variables after that and Dispose of the DataTable and close the connection etc. To set the text of a label you use lbl.Text = "sometext" so once you have it in variables it shoudl be pretty easy.

    Databinding is always done with a DataSource property i believe so if it doesnt have one then i doubt it supports binding but rather just set one of its properties or something.

    if you wanted to do a more advanced solution it is possible to make your own rendercontrols etc so you could just use that but i think underlying that is this anyway..
    Last edited by ghell; 05-03-2006 at 03:55 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •