G
Guest
Hello
Today I had to build a DataGrid very dynamically
<asp:datagrid id="dgTAB" Runat="server" AutoGenerateColumns="False" OnEditCommand="TAB_Edit" OnCancelCommand="TAB_Cancel" OnUpdateCommand="TAB_Update" OnDeleteCommand="TAB_Delete"><Columns><asp:ButtonColumn HeaderText="Delete" Text="Delete" CommandName="Delete" /><asp:EditCommandColumn HeaderText="Edit" EditText="Edit" CancelText="Cancel" UpdateText="Update" /></Columns></asp:datagrid
This is quite a classical one. Then I add in the code behind
BoundColumn col = new BoundColumn ()
col.DataField = ...
col.HeaderText = ...
dgTAB.Columns.Add (col)
I have some of these, I don't know how many without querying my database, which is why I did it that way in the first place
I managed the Delete column very well with a DataKeyField, but I have problems with the Edit Column. By hitting 'Delete', my DataGrid line becomes a line of TextBox which is ok, but hitting 'Update' won't work as I can't access the textboxes' values. It seems that when I enter my TAB_Edit function, the Columns collection only has the two columns Delete & Edit, and not all the BoundColumns I added..
Any suggestions ? Thank
Karine
Today I had to build a DataGrid very dynamically
<asp:datagrid id="dgTAB" Runat="server" AutoGenerateColumns="False" OnEditCommand="TAB_Edit" OnCancelCommand="TAB_Cancel" OnUpdateCommand="TAB_Update" OnDeleteCommand="TAB_Delete"><Columns><asp:ButtonColumn HeaderText="Delete" Text="Delete" CommandName="Delete" /><asp:EditCommandColumn HeaderText="Edit" EditText="Edit" CancelText="Cancel" UpdateText="Update" /></Columns></asp:datagrid
This is quite a classical one. Then I add in the code behind
BoundColumn col = new BoundColumn ()
col.DataField = ...
col.HeaderText = ...
dgTAB.Columns.Add (col)
I have some of these, I don't know how many without querying my database, which is why I did it that way in the first place
I managed the Delete column very well with a DataKeyField, but I have problems with the Edit Column. By hitting 'Delete', my DataGrid line becomes a line of TextBox which is ok, but hitting 'Update' won't work as I can't access the textboxes' values. It seems that when I enter my TAB_Edit function, the Columns collection only has the two columns Delete & Edit, and not all the BoundColumns I added..
Any suggestions ? Thank
Karine