Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to show a GridView column with a chkBox?
Message
 
 
To
28/02/2006 13:13:20
Keith Payne
Technical Marketing Solutions
Florida, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
ASP.NET
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01099896
Message ID:
01310462
Views:
16
>>This is for a web form (ASP.NET 2.0)
>>
>>I am tasked to present a simple query producing two columns: description and a checkbox to activate/deactivate the record.
>>
>>I first query with a SQLDataReader and display Managers and Employees in a Treeview. No problem there.
>>Upon selecting an Employee I query again this time returning the programs this Employee is entitled to. I want a checkbox on a boolean field for the Manager to decide if they allow them access or not. I display this second query in a gridView.
>>
>>Query is simply something like this:
>>
>>SELECT Service.ServID, Service.ServiceDesc, CAST(1 AS bit) AS Entitled from ....
>>
>>
>>I tried binding the grid to a SQLDataReader and the grid shows a checkbox allright but disabled (R/O). I guessed it was because the DataReader is R/O so I tried it with a SQLDataAdapter and DataSet and got the same result. I tried binding to a DataTable instead: same thing.
>>
>>How do I make the checkbox enabled? I don't see an "enabled" property for the column (as I would look for in VFP).
>>
>>TIA
>
>Alex,
>
>The problem is that the row in the grid is not in "edit" mode. Add an Edit/Update/Cancel button column to the grid through the grid builder and the user will be able to edit the checkbox after he clicks on Edit.
>
>In addition to adding the Edit/Update/Cancel button column, a few lines of code are necessary to make the grid editable. You have to hook into the OnItemEdit/OnItemUpdate/OnItemCancel datagrid events and add a couple of lines of code to each. The details are in the .NET help files under DataGrids.
>
>It is also possible to create an no-click editable datagrid, but this requires a lot more code and the use of templated columns instead of the automatic columns from the builder.
>
>In all cases, the datasource of the grid does not affect whether the data is editable on the form. The grid is completely disconnected from the datasource and doesn't care where the data came from.
>
>In ASP.NET, databinding only helps to display the data. It does not assist in writing the data back to the datasource. For instance, if you are using a datatable (or dataset) as the datasource, there are other grid events that have to be hooked into to update the datatable. Then, only when the user clicks the "submit" button will the data be written back to the database through the DataAdapter.Update method.
>
>It is a convoluted but necessary procedure because ASP.NET is disconnected from the original database.

Thanks. I'm trying to add a checkbox for the Approved field in my GridView. I already have GridView build and it's not yet clear to me how to convert textbox into the checkbox...

Reading through http://msdn2.microsoft.com/en-us/magazine/cc163612.aspx at the moment.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform