p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Professional (http://p2p.wrox.com/forumdisplay.php?f=57)
-   -   Selecting Text When Editing Datagrid (http://p2p.wrox.com/showthread.php?t=56615)

elygp April 12th, 2007 09:56 PM

Selecting Text When Editing Datagrid

I have an application that uses a datagrid with EDIT column. The program runs fine and I am able to edit the column of datagrid using the code :

 Datagrid1.EditItemIndex = E.Item.ItemIndex

The code works fine, however, I believe it would be more user friendly if I can make the data of the column to be selected automatcially when EDIT button is clicked. Because what happens in the application is, when you click EDIT button, the data will be displayed for editing, and you will have to click again the mouse to the textbox to edit the data. I would want the focus to go to the textbox automatically so that user can immediately enter new data.

Thanks so much in advance!

zak_willis May 29th, 2007 04:58 PM

Hi there. I won't be posting my code as it is probably over-excessive, but I can tell you how to solve this. The basic problem is that the asp.net 1.1 datagrid doesn't really come up to scratch. Yes, sure you can click an edit column and make it appear as a text box column but what you really want is to be able to have textboxes, checkboxes and dropdowns, you need to be able to create dynamic template columns. I don't think many people would not want to have some form of dynamism as opposed to setting the templates up manually.
For this you need to implement the Itemplate interface and use the Instantiate in method. This allows you to add a textbox, combobox, etc at runtime and set the value to the value of the databinder. A handler is then created that adds the relevant control to the datagridcell. The end result is a datagrid of editable text boxes etc.

Zak Willis
Managing Director of www.blue-rhino.co.uk

All times are GMT -4. The time now is 08:26 AM.

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