retrieve a value from sqldatasource or detailsview

Posted on 2006-05-09
Last Modified: 2012-06-21
I configure a sqldatasource to get one row from my database.
I have now problems binding this to a detailsview and display it. What I really want to do is display it in my own textboxes.
I have created 3 textboxes,  First Name, Last Name,  email address.
How can I retrieve this information from either the sqldatasource or the details view and display it in these textboxes.
Please can you show me an example.


Question by:maxgall
    LVL 12

    Assisted Solution

    Hi maxgall,

    Use a detailsview or formview control, and convert it to a template.  Then you'll have access to the underlying textboxes and be able to modify their properties.

    Author Comment

    Ok I have done for each field and it created templates for each field like below:

                    <asp:TemplateField HeaderText="appDate" SortExpression="appDate">
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("appDate") %>'></asp:TextBox>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("appDate") %>'></asp:TextBox>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("appDate") %>'></asp:Label>

    I am still not sure what to do now.

    txtMyOwnTextbox.text = Textbox1.text    does not work.  How can I now  get the data from TextBox1 into my own Textbox please.
    LVL 6

    Accepted Solution

    For your needs I advise you to use solution like this (totally without sqldatasource):
    'In your case, just use "SQL" objects insted of my "OleDB"
    'Lcesta is TextBox
        Sub Cesta
          lresult.text = ""
          Dim Conn as New  OleDBConnection(ConnString)
          Dim CommText As String
          Dim Comm as New OleDBCommand
          dim dread as OleDBDataReader
          Comm.Connection = Conn
          Comm.CommandText =   "select directory_path from all_directories where directory_name = upper('datain')"
            dread = Comm.ExecuteReader()
            if then
              Lcesta.text = dread.getvalue(0) + "/"
            end if
          catch ex as Exception
            lresult.text = ex.message
          end try
        End Sub

    LVL 6

    Expert Comment

    One more notice.
    There should be also command for closing the Reader:
            end if
          catch ex as Exception

    Author Comment

    Both solutions are helpful to me. If one of you could still answer my question from 2.02 the I will split the points
    300 / 200

    txtMyOwnTextbox.text = Textbox1.text    does not work.  How can I now  get the data from TextBox1 into my own Textbox please.


    LVL 6

    Expert Comment

    When you have 2 columns (fisrt name of value, second the value) in your detailsview then this should work:
    MyOwnTextBox.Text = CType(DetailsView1.Rows(0).Cells(1).FindControl("TextBox1"),TextBox).Text

    Author Comment

    thanks to both of you. I will try out both solutions.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now