Groups | Blog | Home
all groups > asp.net datagrid control > july 2005 >

asp.net datagrid control : Client side event for datagrid control


Xavier Pacheco
7/28/2005 8:13:50 AM
This is probably a simple one, but I cannot seem to find an example.

I have a datagrid with each row containing

Checkbox | Textbox | Validation

When the checkbox column is checked for a given row, TextBox is
enabled, initialized with a value and the validation is enabled.

When the checkbox column is unchecked, Textbox is disabled, initialized
to Emtpy and validation is disabled.

Any pointers?
Lamont
7/29/2005 2:58:04 PM
In your datagrids ItemDataBound event you have to do something like this...

szCheckScript &= "document.frmCC.dgContracts__ctl" & _
e.Item.ItemIndex + 2 & "_" & e.Item.Cells(7).Controls(7).ID & _
".disabled=false;"
szUnCheckScript &= "document.frmCC.dgContracts__ctl" & _
e.Item.ItemIndex + 2 & "_" & e.Item.Cells(7).Controls(7).ID & _
".disabled=true;"

tmpChkBox = CType(e.Item.Cells(2).Controls(1), CheckBox)
tmpChkBox.Attributes.Add("onclick", "if (this.checked) {" & _
szCheckScript & _
"} else {" & _
szUnCheckScript & _
"}")

View the source on your page when you run it and look at the names .NET
assigns to the checkbox controls in the datagrid. That will explain all the
ctl code where it is getting the name of the control.

Hope that makes sense.
--
Lamont - OKC Developer


[quoted text, click to view]
AddThis Social Bookmark Button