473,585 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

databinding - datatextfield questions

Hi

I am attempting to bind data to a dropdownlist. Currently the below code
will bind a persons last name just find using the datatextfield. What I
would like to do though, is also be able to bind there First Name as well
into that datatextfield, so that when the drop down list is displayed, they
see a Last Name, First Name, rather than just a persons last name.

cmdname = New SqlClient.SqlCo mmand("SELECT id, lname, fname from
app_personal", conn)
dtrname = cmdname.Execute Reader()
ddlname.DataSou rce = dtrname
ddlname.DataTex tField = "lname"
ddlname.DataVal ueField = "id"

ddlname.DataBin d()
dtrname.Close()

Any help would be much appreciated.

Are there any other ways apart from the sql method?..eg: New
SqlClient.SqlCo mmand("SELECT id, lname, fname, rtrim(fname) + ' ' +
rtrim(lname) as fullname from app_personal", conn)

Pls advise.

Thanks

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Apr 2 '07 #1
1 1193
Howdy,

I quess you use vb.net:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Load

If Not IsPostBack Then
PopulatePeople( )
End If

End Sub

Private Sub PopulatePeople( )

Dim query As String = "select id, lname, fname from app_personal"
Dim table As New DataTable

Using connection As New SqlConnection(C onnectionString )
Dim adapter As New SqlDataAdapter( query, connection)
connection.Open ()
adapter.Fill(ta ble)
End Using

' data is retreived from database,
' concatenation is performed locally
table.Columns.A dd("fullName", GetType(String) , "fname + ' ' + lname")

people.DataValu eField = "id"
people.DataText Field = "fullName"
people.DataSour ce = table
people.DataBind ()

End Sub

--
Milosz
"Eric Layman" wrote:
Hi

I am attempting to bind data to a dropdownlist. Currently the below code
will bind a persons last name just find using the datatextfield. What I
would like to do though, is also be able to bind there First Name as well
into that datatextfield, so that when the drop down list is displayed, they
see a Last Name, First Name, rather than just a persons last name.

cmdname = New SqlClient.SqlCo mmand("SELECT id, lname, fname from
app_personal", conn)
dtrname = cmdname.Execute Reader()
ddlname.DataSou rce = dtrname
ddlname.DataTex tField = "lname"
ddlname.DataVal ueField = "id"

ddlname.DataBin d()
dtrname.Close()

Any help would be much appreciated.

Are there any other ways apart from the sql method?..eg: New
SqlClient.SqlCo mmand("SELECT id, lname, fname, rtrim(fname) + ' ' +
rtrim(lname) as fullname from app_personal", conn)

Pls advise.

Thanks

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Apr 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2718
by: Martin | last post by:
Hi, Please can somebody explain how databinding is done on a checkbox list. I have the follwoing code which I would have thought was enough to databind a checkbox, but apparently not. The data is coming from an sql server database "Name" is a text feild "Valid" is a bit field
4
4203
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox), SqlConnection (sqlConnection), SqlDataAdapter (daLookupData), SqlDataAdapter (daData), DataSet (dsLookupData), and DataSet (dsData), all created via the IDE...
1
2151
by: Joe Gass | last post by:
I'd like to bind some xml to a dropdownlist <engines> <engine name="test1" id="1" /> <engine name="test2" id="2" /> </engines> If I do: ddlEngines.DataSource = xmlDoc.SelectNodes("/engines/engine")
8
1666
by: tshad | last post by:
Can you databind a dropdownlist to another dropdownlist? I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next as the dataReader can only be read once. I tried: ExperienceLevel.DataSource=dbReader ExperienceLevel.DataTextField= "Description"
1
2813
by: dieter | last post by:
Two-way databinding (as described in http://dotnetjunkies.com/QuickStartv20/aspnet/doc/data/templates.aspx) works fine for me if I use it within aspx-files. However, I would like to use it my codehind file and I don't know how to get it work since I did not find any equivalent for "Bind" to use in my ITemplate derived class. For my...
2
2183
by: musosdev | last post by:
Hi guys I have an asp:ListBox on my form, which I'm populating with a DataReader, using DataSource/DataBind. The problem is that the main field I want to use for DataTextField, "Company" in this case, is often blank. How can I get the DataBinding to go... "if Company is blank, use ContactName, else use Company"
1
14305
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. Both the grid and the dropdown box are retrieving and displaying data fine, I just cant bind the two together. I followed the instructions in the...
3
8683
by: John | last post by:
I'm getting this error when i'm trying to databind my dataset to a dropdown: DataBinding: 'System.Data.DataRowView' does not contain a property with the name '12/12/2003' but if I do a response.write I can see the dates fine, what is causing this error? code: dYear.DataSource = dsYearofSales.Tables; string strYearofSales =...
0
1320
by: brian.newman | last post by:
I've created a dropdownlist whose values are drawn from an Access database. This list of items represents a user account. In the same record is a boolean field which records whether the user is an administrator. On my web form, I want a checkbox labelled "Is Admin" which will take the appropriate value from the Access database depending on...
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.