Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 September 5th, 2003, 03:06 AM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid - edit mode

Hi.
I would ask, if it is possible to display data from database
in other format than Textbox (for example CheckBox), when I turn Datagrid into edit-mode.
But autogenerate columns must be set to true.
Thanks.

 
Old September 5th, 2003, 08:37 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is a way, but its a little complicated.

You can work with the ItemDataBound event of the datagrid to manipulate each row of a datagrid as it's bound. In this method, you can access "e" which is the DataGridEventArgs. Off that is "Item" which is a DataGridItem. On it is the "Cells" collection, then off one item of that collection ("Cells(n)") you can access the "Controls" collection. When the datagrid draws in edit mode you will typically have a single control in the cell, this will be the textbox. Potentially, you could remove the textbox and replace it with another server control of your choosing. Then when you hit the "Update" datagrid method for that row, you'll have to dig out the value of your new server control in the same manner that you found and replaced the text box...
CType(e.Item.Cells(n).Controls(0),ControlType).ControlSpecificProperty

If your plan is to handle every column the same, then you just need to loop thru "e.Item.Cells" to modify each one.

Keep in mind that in the "DataItemBound" method, you'll need to check each item to see if it is an "EditItem" so you only modify the selected row.

Why must you use autogenerate columns? This is a bit easier with template columns.

Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when using DataGrid edit mode?? tryston02 ASP.NET 1.0 and 1.1 Basics 2 November 22nd, 2004 07:00 PM
Edit mode I do not see the ddlist datagrid macupryk General .NET 0 October 10th, 2004 09:23 PM
Datagrid - edit mode Programator ASP.NET 1.0 and 1.1 Professional 1 September 5th, 2003 08:38 AM
Datagrid - edit mode Programator Classic ASP Professional 0 September 5th, 2003 03:13 AM





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