Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
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 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 June 23rd, 2004, 07:46 PM
Registered User
 
Join Date: Jun 2004
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

 
Old June 23rd, 2004, 11:29 PM
Registered User
 
Join Date: Jun 2004
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****************

 
Old June 27th, 2004, 02:12 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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!)





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





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