Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 23rd, 2004, 07:46 PM
Registered User
 
Join Date: Jun 2004
Location: St KIlda, Victoria, Australia.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid column headertext => CheckboxList ?

Hi everyone,

Hope you can help...

Heres my situation. I fairly new to ASP.NET with Databases, and I am working through the Wrox book at the moment while creating a fairly simple web application for work.

So far I have a datagrid populated from SQL containing a LOT of user information. Infact, far too much. There are too many fields, but the users require them all.

What I want to do is generate checkboxes from each field in the table and bind them to the datagrid so that users can turn off/on the columns they dont want to see.

So, I just want to know how I can bind a CheckboxList to the Datagrid HeaderText...

If someone can answer this, I will be wrapped! Becuase this is the only thing holding me back so far. :)

Regards,
Euan

Reply With Quote
  #2 (permalink)  
Old June 23rd, 2004, 11:29 PM
Registered User
 
Join Date: Jun 2004
Location: St KIlda, Victoria, Australia.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I have got something fairly dodgy together now if anyone else is interested.

Its the best I could come up with, and please ... I am a total beginner so dont tell me my code is crap :)

So far it has worked ok. But if anyone has suggestions for optimising the code, or something simpler I would GREATLY appreciate it!

Regards,
Euan

********SNIP**************

Sub Page_Load(Source As Object, E As EventArgs)

    Dim StrConnection As String = ConfigurationSettings.AppSettings("CurrentClients" )
    Dim ClientsConn As SqlConnection = New SqlConnection(StrConnection)
    Dim schemaDA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='CURRENT_CLIENTS'", ClientsConn)
    Dim ClientsDA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM CURRENT_CLIENTS", ClientsConn)
    Dim schemaTable As DataTable = New DataTable
    Dim ClientsTable As DataTable = New DataTable
    ClientsDA.Fill(ClientsTable)
    schemaDA.Fill(schemaTable)
    dgClients.datasource = ClientsTable
    dgSchema.datasource = SchemaTable
    dgSchema.databind()
    dgClients.databind()

    ckbEmployees.datasource = schemaTable
    ckbEmployees.DataTextField = "COLUMN_NAME"
    ckbEmployees.DataValueField = "COLUMN_NAME"
    ckbEmployees.Databind()


    ClientsConn.close()


End Sub

************SNIP****************

Reply With Quote
  #3 (permalink)  
Old June 27th, 2004, 02:12 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You might be able to optimize this by binding directly to the DataTable's Columns collection. Then you wouldn't need to make a secondary query to the schema of the database.

(Might I add that for a "beginner", as you claim to be, that's not bad code at all. Figuring out the schema stuff is pretty good!)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Column Display degie C# 2005 0 May 28th, 2007 01:48 AM
Format Datagrid column lamdog ASP.NET 1.0 and 1.1 Basics 4 March 23rd, 2005 09:37 AM
Find column in datagrid Lesviper VB How-To 0 March 9th, 2005 07:54 AM



All times are GMT -4. The time now is 09:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.