Editable Datagrid (Cells)
Hi!
I want to have a Datagrid, where , I can edit cells (and not rows) , on clicking at it. When I click on a cell, it should become a dropdown , from where I can choose an item. (There should be no Edit link or a button) On clicking the Update button, it should update all the cells , which were edited. Is this is doable in a datagrid? Will DHTML come into picture. Can anyone please guide me to an appropiate article on this, which could give me a start?
Thanks.
Re: Editable Datagrid (Cells)
It is quite easy to do.
http://www.codeproject.com/KB/webfor...viewCells.aspx
Though it is using GridView, changing it to DataGrid should not be a problem.
This can be easily done using JS too. In the ItemDataBound of DG, add a JS onclick command on the cell and make it to display the dropdownlist or textbox or whatever.
Re: Editable Datagrid (Cells)
Re: Editable Datagrid (Cells)
Quote:
This can be easily done using JS too. In the ItemDataBound of DG, add a JS onclick command on the cell and make it to display the dropdownlist or textbox or whatever.
Can you please send me an example or an article? That will be a great help.
Thanks
Re: Editable Datagrid (Cells)
Try this out first, then tell us where you're stuck. There are an infinite number of things you can do in the databound events, so there isn't a code sample for every possibility.
Re: Editable Datagrid (Cells)
Ok...
Step 1) - I will have two controls in ItemTemplate. First, to display the data. Second will remain invisible. This will become visible only when I click on the cell.
Step 2) - Add a JS (bind to the click event of a cell), which diplays my invisible control? Pls help me in this.
The article says "Within the RowDataBound (ItemDataBound) event each cell of the row is looped through and has a click event added. Is this needed?
Thanks
Re: Editable Datagrid (Cells)
Quote:
Originally Posted by sinha
Ok...
Step 1) - I will have two controls in ItemTemplate. First, to display the data. Second will remain invisible. This will become visible only when I click on the cell.
Good.
Quote:
Step 2) - Add a JS (bind to the click event of a cell), which diplays my invisible control? Pls help me in this.
The article says "Within the RowDataBound (ItemDataBound) event each cell of the row is looped through and has a click event added. Is this needed?
Absolutely needed. In the ItemDataBound event, do something like
e.Cells[4].Attributes.Add("onClick","document.getElementById('" & hiddenclientid & "').visible = true;");
Where 4 is the cell number with the hidden element, hiddenclientid is the .ClientID property of the hidden element for that itemtemplate. You need to get this using e.FindControl().
(It may be e.Item.Cells and e.Item.FindControl())
Re: Editable Datagrid (Cells)
Thanks Mendhak. I have incorporated it successfully.
Re: Editable Datagrid (Cells)
Good work! Add [Resolved]