DataGrid : dynamic BoundColumn & OnUpdateCommand

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
 
G

Guest

(an error slipped through while writing the message...

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 'Edit' (and not 'Delete', my mistake in the first msg), 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top