DataGrid & Checkbox Template Columns

J

J

Hi,
I've got a simple datagrid that is populated by an adapter from SQL. I
have two template columns - one with a checkbox and one with a textbox.
I am allowing users to indicate which rows to remove from the grid by
checking the boxes - the boxes don't autopostback, i want to remove all
selected rows at once on page postback - my problem is:

I can find now way of iterating through the datagrid rows to check
whether each checkbox in the template column is checked or not!! Does
anyone know of a way to do this?
 
E

Elton Wang

foreach (DataGridItem item in datagrid.Items)
{
CheckBox chk = item.FindControl(CheckBox_ID) as CheckBox;
bool checked = chk.Checked;
// ...
}

HTH
 
E

Elton Wang

If it's in template column, it should look like

<asp:TextBox Runat="server" ID="txt"></asp:TextBox>

You can get the textbox by

(TextBox)e.Item.FindControl("txt")

But if you use BoundColumn for in-place editing, you should use

(TextBox)e.Item.Cells[col_index]Controls[0]

HTH
 
D

Doru Roman

So it is not possible to determine the type of the control if you are not
sure what it is and what ID has, when using bound columns, isn't it?
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top