473,513 Members | 2,554 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.SqlCommand("SELECT id, lname, fname from
app_personal", conn)
dtrname = cmdname.ExecuteReader()
ddlname.DataSource = dtrname
ddlname.DataTextField = "lname"
ddlname.DataValueField = "id"

ddlname.DataBind()
dtrname.Close()

Any help would be much appreciated.

Are there any other ways apart from the sql method?..eg: New
SqlClient.SqlCommand("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 1187
Howdy,

I quess you use vb.net:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
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(ConnectionString)
Dim adapter As New SqlDataAdapter(query, connection)
connection.Open()
adapter.Fill(table)
End Using

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

people.DataValueField = "id"
people.DataTextField = "fullName"
people.DataSource = 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.SqlCommand("SELECT id, lname, fname from
app_personal", conn)
dtrname = cmdname.ExecuteReader()
ddlname.DataSource = dtrname
ddlname.DataTextField = "lname"
ddlname.DataValueField = "id"

ddlname.DataBind()
dtrname.Close()

Any help would be much appreciated.

Are there any other ways apart from the sql method?..eg: New
SqlClient.SqlCommand("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
2714
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
4189
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
2146
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
1662
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
2809
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
2178
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
14299
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
8674
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
1316
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
7270
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
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
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
5704
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...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
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
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.