Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Really simple, but im missing something?! Binding to a label from a datasource in .net2 c#

Really simple, but im missing something?! Binding to a label from a datasource in .net2 c#

Scheduled Pinned Locked Moved ASP.NET
csharpwpfwcfhelptutorial
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AdamskiR
    wrote on last edited by
    #1

    Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam

    G H P 3 Replies Last reply
    0
    • A AdamskiR

      Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam

      G Offline
      G Offline
      gauthee
      wrote on last edited by
      #2

      Didnt the DataBinder.Eval(Container.DataItem,"columnname") work???

      Gautham

      A 1 Reply Last reply
      0
      • G gauthee

        Didnt the DataBinder.Eval(Container.DataItem,"columnname") work???

        Gautham

        A Offline
        A Offline
        AdamskiR
        wrote on last edited by
        #3

        Thanks for the reply. I dont know, how would i go about adding this? my heads in a right muddle! Id need to reference the datasource somewhere first though wouldnt i? How do I do this? Adam

        G 1 Reply Last reply
        0
        • A AdamskiR

          Thanks for the reply. I dont know, how would i go about adding this? my heads in a right muddle! Id need to reference the datasource somewhere first though wouldnt i? How do I do this? Adam

          G Offline
          G Offline
          gauthee
          wrote on last edited by
          #4

          No Problem!!! Lets say that you have a gridview1 and the datasource given to the gridview1 is ds!! Assume that the resultant ds has a table with 5 rows and 3 columns col a, col b, col c. No in your grid under the itemtemplate you would have added the label right! there you would just include the binding logic ex: DataBinder.Eval(Container.DataItem,"col a") ....... ....... ...... ......

          Gautham

          A 1 Reply Last reply
          0
          • A AdamskiR

            Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam

            H Offline
            H Offline
            Harini N K
            wrote on last edited by
            #5

            Hi There are lots of examples for form view using SQL Data Source. Here is an example to bind data in labels using VS.Net 2005 (C#.net 2.0) Simply drag and drop SQL Data source in your application. Right click the Data source, click Configure Data Source. If this is the first time you are connecting to Database then Click New connection, Type Server Name, User Name & Password. Select database from the list after entering valid user name and password. Connection String will be populated automatically in the list. Click next, select table from the list. You can modify your query later using the SELECT property of SQLDataSource. If you don’t want SQLDatasource, you can add a connection string in Web.config and use the same. No need to worry about that now. You need to explore more on this. For beginners, use SQL Data source. Try without DataSource later as most applications use Stored Procedures. Now add Form or Details or Grid view in your application; go to DataSourceID property of the control (formview or detailsview or gridview). Select DataSourceID from the list as you have added in your application. By default all fields will be bind automatically. Just take a note: .net uses the following expression for binding text:

            1. <%# DataBinder.Eval(Container.DataItem,”columnname”%> - for gridview
            2. <%# Bind(“Columnname”) %> - for formview or detailsview
            3. <%# Eval(“Columnname”) %> - for formview or detailsview

            Try other controls like GridView. All the best

            Rate this message. Thank you. Harini :)

            A 1 Reply Last reply
            0
            • G gauthee

              No Problem!!! Lets say that you have a gridview1 and the datasource given to the gridview1 is ds!! Assume that the resultant ds has a table with 5 rows and 3 columns col a, col b, col c. No in your grid under the itemtemplate you would have added the label right! there you would just include the binding logic ex: DataBinder.Eval(Container.DataItem,"col a") ....... ....... ...... ......

              Gautham

              A Offline
              A Offline
              AdamskiR
              wrote on last edited by
              #6

              Its not linked with a gridview or anything as an item template, that part i can do. Basically what i want is that there is a list of records in a listbox. You then can select a record which will then close the listbox and populate some labels with the persons email, name etc. This is so that I can easily pull these records as I will want to add these into the database as it is part of a wizard form i am building for people to fill in. Hope this makes sense. Thanks Adam

              1 Reply Last reply
              0
              • H Harini N K

                Hi There are lots of examples for form view using SQL Data Source. Here is an example to bind data in labels using VS.Net 2005 (C#.net 2.0) Simply drag and drop SQL Data source in your application. Right click the Data source, click Configure Data Source. If this is the first time you are connecting to Database then Click New connection, Type Server Name, User Name & Password. Select database from the list after entering valid user name and password. Connection String will be populated automatically in the list. Click next, select table from the list. You can modify your query later using the SELECT property of SQLDataSource. If you don’t want SQLDatasource, you can add a connection string in Web.config and use the same. No need to worry about that now. You need to explore more on this. For beginners, use SQL Data source. Try without DataSource later as most applications use Stored Procedures. Now add Form or Details or Grid view in your application; go to DataSourceID property of the control (formview or detailsview or gridview). Select DataSourceID from the list as you have added in your application. By default all fields will be bind automatically. Just take a note: .net uses the following expression for binding text:

                1. <%# DataBinder.Eval(Container.DataItem,”columnname”%> - for gridview
                2. <%# Bind(“Columnname”) %> - for formview or detailsview
                3. <%# Eval(“Columnname”) %> - for formview or detailsview

                Try other controls like GridView. All the best

                Rate this message. Thank you. Harini :)

                A Offline
                A Offline
                AdamskiR
                wrote on last edited by
                #7

                Thanks for your reply. BUt i wasnt looking to have the records in a form/details view as this would cause me problems on submitting the data as how would i find the actual labels within the controls when i want to submit the form?

                1 Reply Last reply
                0
                • A AdamskiR

                  Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam

                  P Offline
                  P Offline
                  Paddy Boyd
                  wrote on last edited by
                  #8

                  Very simple e.g., myLabel.text = dataTable.Rows(0).Items(0) It depends on what your datasource is...

                  A 1 Reply Last reply
                  0
                  • P Paddy Boyd

                    Very simple e.g., myLabel.text = dataTable.Rows(0).Items(0) It depends on what your datasource is...

                    A Offline
                    A Offline
                    AdamskiR
                    wrote on last edited by
                    #9

                    Its a sqldatasource. What code would i need in to create the datatable from this in the first place? Thanks

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups