DataGridColumnCollection

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 'Edit', 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... no way to get to the usual e.Item.Cells[cellnumber].Controls[0]

Any suggestions ? Thank
Karin
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top