Re: Checkbox in datagrid to enable disable textboxes



Thanks again dave for your help.

Unfortunately, I do not want to disable the entire row in the grid, just the
input cells.
I was able to create code that will work. It may not be the most eligant,
but at least it works.

Thanks again for your help.

Code (if interested):
<script language="javascript">
function chkMappedClicked(chkB)
{
//debugger;
var a = chkB.parentNode.parentNode.getElementsByTagName("INPUT")
for (var i=1; i<a.length; i++) //dont want to include a[0]
{
if (a[i].type == "text")
{
a[i].disabled = !chkB.checked
}
}

chkB.parentElement.parentElement.children.item(5).disabled = !chkB.checked;
chkB.parentElement.parentElement.children.item(6).disabled = !chkB.checked;
}
</script>

Private Sub dgKeyControl_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgKeyControl.ItemDataBound
Dim chk As CheckBox

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem
Then
If Not e.Item.Cells(0).Controls(1).FindControl("chkMapped") Is
Nothing Then
chk =
CType(e.Item.Cells(0).Controls(1).FindControl("chkMapped"), CheckBox)

If chk.Checked Then


EnableTextBoxes(CType(e.Item.Cells(3).Controls(1).FindControl("txtCORef"),
TextBox), True)

EnableTextBoxes(CType(e.Item.Cells(4).Controls(1).FindControl("txtKCRef"),
TextBox), True)
e.Item.Cells(5).Enabled = True
e.Item.Cells(6).Enabled = True
Else

EnableTextBoxes(CType(e.Item.Cells(3).Controls(1).FindControl("txtCORef"),
TextBox), False)

EnableTextBoxes(CType(e.Item.Cells(4).Controls(1).FindControl("txtKCRef"),
TextBox), False)
e.Item.Cells(5).Enabled = False
e.Item.Cells(6).Enabled = False
End If
End If
End If
End Sub

Private Sub EnableTextBoxes(ByRef txtBox As TextBox, ByVal boolEnabled
As Boolean)
txtBox.Enabled = boolEnabled
End Sub

"Dave Anderson" wrote:

Ben wrote:
It appears i was a little too quick with my last repsonse. Your code
works great, but i founda nother problem.

in server side code, im disabling the same checkboxes by using:
funct2(CType(e.Item.Cells(5).Controls(1).FindControl("chkSOX"),
CheckBox), True)
where funct2 is:
Private Sub funct2(ByVal chkBox As CheckBox, ByVal boolEnabled As
Boolean) chkBox.Enabled = boolEnabled
End Sub

now, in your code, im trying to re-enable the controls, however it
doesnt work. Ive looked at the html and found that the checkboxes
are being wrapped in a 'span' and the span is being disabled:
<span disabled="disabled">

any suggestions to getting rid of the <span>?

Rather than get rid of it, look for a solution that is more generic, so you
no longer care about superfluous markup. If you really want to touch all of
the elements in the same row, compute the containing row on the fly. I
didn't have time to make this more elegant, but this ought to work. Use your
same function, but work outward to find the nearest containing TR element.
Modify this line...

var a = chkB.parentNode.parentNode.getElementsByTagName("INPUT")

....to:

var a = ContainingElement(chkB,"tr").getElementsByTagName("INPUT")

....making sure you have a function like this:

function ContainingElement(node,tag) {
tag = (tag || "").toUpperCase()
return
node.parentNode?node.parentNode.tagName==tag?node.parentNode:ContainingElement(node.parentNode,tag):node
} /* spaces removed to minimize wrapping when I post this */




--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.



.



Relevant Pages

  • Re: Check box problem is not solved
    ... Private Sub Form_Current ... permitted to check or uncheck the checkboxes if the objnumber value is ... disabling certain check boxes, we might be able to suggest another way to ... any record in those 100 records is "16" then the corresponding CheckBox ...
    (microsoft.public.access.modulesdaovba)
  • Re: Checkbox error
    ... I have managed to get the checkbox to work with the coding below, that is, I ... I deselect the box and the field blank as wanted. ... Private Sub ASSIGNEDCHECKBOX_AfterUpdate ... Disabling the checkbox seems a bad idea: how would the user be able to ...
    (microsoft.public.access.forms)
  • Re: Need a way to tell if a System.Windows.Forms.Button is "depressed" (pushed down)
    ... > Private Sub CheckBox1_MouseDown(ByVal sender As Object, ... >>> The following is a sample of a CheckBox that has an IsPushed property. ... >>> same code works for CheckBox, RadioButton, & Button class in .NET. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need a way to tell if a System.Windows.Forms.Button is "depressed" (pushed down)
    ... > Private Sub CheckBox1_MouseDown(ByVal sender As Object, ... >>> The following is a sample of a CheckBox that has an IsPushed property. ... >>> same code works for CheckBox, RadioButton, & Button class in .NET. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need a way to tell if a System.Windows.Forms.Button is "depressed" (pushed down)
    ... > Private Sub CheckBox1_MouseDown(ByVal sender As Object, ... >>> The following is a sample of a CheckBox that has an IsPushed property. ... >>> same code works for CheckBox, RadioButton, & Button class in .NET. ...
    (microsoft.public.dotnet.framework.windowsforms)