Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1029
  • Last Modified:

retrieve a value from sqldatasource or detailsview

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.

thanks

Max
0
maxgall
Asked:
maxgall
  • 3
  • 3
2 Solutions
 
ProactivationCommented:
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.
0
 
maxgallAuthor Commented:
Ok I have done for each field and it created templates for each field like below:

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

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.
0
 
the_paabCommented:
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)
      Conn.Open()
      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')"
      try
        dread = Comm.ExecuteReader()
        if dread.read then
          Lcesta.text = dread.getvalue(0) + "/"
        end if
      catch ex as Exception
        lresult.text = ex.message
      finally
        Conn.Close
      end try
    End Sub

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
the_paabCommented:
One more notice.
There should be also command for closing the Reader:
...
        end if
        dread.Close
      catch ex as Exception
...
0
 
maxgallAuthor Commented:
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.

thanks

Max
0
 
the_paabCommented:
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
0
 
maxgallAuthor Commented:
thanks to both of you. I will try out both solutions.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now