Re: Checkbox in datagrid to enable disable textboxes
- From: Ben <ben_1_ AT hotmail DOT com>
- Date: Thu, 22 Jun 2006 05:27:01 -0700
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.
- References:
- Re: Checkbox in datagrid to enable disable textboxes
- From: Dave Anderson
- Re: Checkbox in datagrid to enable disable textboxes
- From: Dave Anderson
- Re: Checkbox in datagrid to enable disable textboxes
- From: Dave Anderson
- Re: Checkbox in datagrid to enable disable textboxes
- Prev by Date: Re: Help with treeview node paths??!
- Next by Date: Weird result
- Previous by thread: Re: Checkbox in datagrid to enable disable textboxes
- Next by thread: Re: Checkbox in datagrid to enable disable textboxes
- Index(es):
Relevant Pages
|