CheckBox and Datagrid

  • Thread starter Thread starter Andre
  • Start date Start date
A

Andre

Hi,

I need some help with automatically generated checkbox in my datagrid,
i'm searching everywhere and can't find a way to do this.

In my datagrid i will always have more than one line, with one checkbox
on each line (each line is an option for our costumers).
But i want to :

- have autopostback set to true only on the first (or any other,
selected before the databind) checkbox
- when the form is sudmited, check wich checkbox is checked, so i can
view what the customers have selected, but they have all the same ID,
because if i try to assign a different ID to each one, like this :
<asp:CheckBox Runat=server ID=<%# container.dataitem("serviceno")%>
AutoPostBack=True/> i receive this error : '<%#
container.dataitem("serviceno")%>' is not a valid identifier.

Did someone have any idea for this ?

Thank you.
 
call all the checkboxes the same ID

then, when you want to find out their values, do this

dim tempcheckbox as checkbox

for counter = 0 to MyDataGrid.Items.Count - 1
tempcheckbox =
CType(Mydatagrid.Items(counter).FindControl("checkboxname"), CheckBox)

if tempcheckox.checked then
'do whatever.
end if
next

you might have to use mydatagrid.items(counter).cells(x).FindControl instead
(where x is the index of the cell with the checkbox), i'm not sure.

R
 
Back
Top