K
Karine Proot
Hello,
(I'm impressed there's a dedicated newsgroup for datagrids !)
I am trying to build a webpage with a list showing some database table names displaying as links. Clicking on one of them will fill a datagrid with it, providing Edit and Delete functionnalitites.
Displaying the datagrid went great, and deleting items is ok also. My problem is with editing.
Here is the datagrid :
<asp:datagrid id="dgTAB" Runat="server" AutoGenerateColumns="False" OnEditCommand="TAB_Edit"
OnCancelCommand="TAB_Cancel" OnUpdateCommand="TAB_Update" OnDeleteCommand="TAB_Delete"><Columns><asp:ButtonColumn HeaderText="Supprimer" Text="<img src='../images/boutons/supprimer.gif' />" CommandName="Delete" /><asp:EditCommandColumn HeaderText="Modifier" EditText="<image src='../images/boutons/modifier.gif'></image>"
CancelText="<image src='../images/boutons/non.gif'></image>" UpdateText="<image src='../images/boutons/oui.gif'></image>" /></Columns></asp:datagrid>
I add the other columns in the code behind :
col = new BoundColumn ();
col.DataField = ...;
col.HeaderText = ...;
dgTAB.Columns.Add (col);
Now when I click on 'Edit', all the columns are filled with Textboxes containing the old value, which is perfect.
public void TAB_Edit (Object sender, DataGridCommandEventArgs e)
Here, e.Item has only two cells (the one for Delete and the one for Edit). I read this is normal in http://msdn.microsoft.com/library/d...rolsdatagridcolumncollectionclassaddtopic.asp :
"The DataGrid control does not store the contents of its Columns collection into the view state. To add or remove a column dynamically, you must programmatically add or remove the column each time the page is refreshed. Provide a Page_Init function that adds or removes the column before the DataGrid control can reload its state and rebuild itself. Otherwise, the changes to the Columns collection are not reflected in the DataGrid control when it is displayed."
But, if I do add the columns in Page_Init, I have to write again the "col.DataField=" part, which will overwrite anything changed in the textboxes.
How do I get the Textboxes new values ?
Or did I make something wrong ?
Karine Proot
(I'm impressed there's a dedicated newsgroup for datagrids !)
I am trying to build a webpage with a list showing some database table names displaying as links. Clicking on one of them will fill a datagrid with it, providing Edit and Delete functionnalitites.
Displaying the datagrid went great, and deleting items is ok also. My problem is with editing.
Here is the datagrid :
<asp:datagrid id="dgTAB" Runat="server" AutoGenerateColumns="False" OnEditCommand="TAB_Edit"
OnCancelCommand="TAB_Cancel" OnUpdateCommand="TAB_Update" OnDeleteCommand="TAB_Delete"><Columns><asp:ButtonColumn HeaderText="Supprimer" Text="<img src='../images/boutons/supprimer.gif' />" CommandName="Delete" /><asp:EditCommandColumn HeaderText="Modifier" EditText="<image src='../images/boutons/modifier.gif'></image>"
CancelText="<image src='../images/boutons/non.gif'></image>" UpdateText="<image src='../images/boutons/oui.gif'></image>" /></Columns></asp:datagrid>
I add the other columns in the code behind :
col = new BoundColumn ();
col.DataField = ...;
col.HeaderText = ...;
dgTAB.Columns.Add (col);
Now when I click on 'Edit', all the columns are filled with Textboxes containing the old value, which is perfect.
public void TAB_Edit (Object sender, DataGridCommandEventArgs e)
Here, e.Item has only two cells (the one for Delete and the one for Edit). I read this is normal in http://msdn.microsoft.com/library/d...rolsdatagridcolumncollectionclassaddtopic.asp :
"The DataGrid control does not store the contents of its Columns collection into the view state. To add or remove a column dynamically, you must programmatically add or remove the column each time the page is refreshed. Provide a Page_Init function that adds or removes the column before the DataGrid control can reload its state and rebuild itself. Otherwise, the changes to the Columns collection are not reflected in the DataGrid control when it is displayed."
But, if I do add the columns in Page_Init, I have to write again the "col.DataField=" part, which will overwrite anything changed in the textboxes.
How do I get the Textboxes new values ?
Or did I make something wrong ?
Karine Proot