Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2003, 05:27 PM
Authorized User
 
Join Date: Jul 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listbox (checkbox list) Problem

Hello,

I am having trouble populating the DataTextField of a CheckBox List with data from more than one field of a database. If I only use one field it works fine, but as soon as i add a second I receive and error. Here is a sample of the code (using vb.net)

        strSQL = ""
        strSQL += " select id, firstname, lastname"
        strSQL += " from approvers"

        objConn = New SqlConnection(strConn)
        objAdapter = New SqlDataAdapter(strSQL, objConn)
        objAdapter.Fill(objDS, "approver")

        cblApprovers.DataSource = objDS.Tables("approver").DefaultView
        cblApprovers.DataTextField = "lastname" & ", " & "firstname"
        cblApprovers.DataValueField = "id"
        cblApprovers.DataBind()

If I just use "firstname" or "lastname" it run fine. I am hoping to populate a checkbox list that will show like this

"<lastname>, <firstname>"

Can you please assist?

Thanks

Craig Jones

__________________
Craig
-----------------------
there is no place like 127.0.0.1
 
Old November 10th, 2005, 07:01 AM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please try the code below, i use this for my purpose.
strSQL = ""
        strSQL += " select id, lastname + ', ' + firstname as NewText"
        strSQL += " from approvers"

        objConn = New SqlConnection(strConn)
        objAdapter = New SqlDataAdapter(strSQL, objConn)
        objAdapter.Fill(objDS, "approver")

        cblApprovers.DataSource = objDS.Tables("approver").DefaultView
        cblApprovers.DataTextField = "NewText"
        cblApprovers.DataValueField = "id"
        cblApprovers.DataBind()





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add checkbox in a listbox rakeshbindal4 ASP.NET 2.0 Professional 0 August 24th, 2006 03:21 AM
checkbox problem sarvesh189 ADO.NET 1 March 21st, 2005 03:44 AM
Checkbox list validation lily611 General .NET 6 December 10th, 2004 03:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.