Javascript with Datagrid items.

T

tshad

I need to do some work with Javascript and my datagrid controls.

I want to do something like:
*********************************************************
function CheckQuestion()
{
var checkBox = document.getElementById('_ctl0_SecurityStandard');
if (checkBox.checked)
{
dropDown = document.getElementById('_ctl0_SecretQuestion');
dropDown.disabled = false;
textBox = document.getElementById('_ctl0_SecretQuestionText');
textBox.value = "";
textBox.disabled = true;
}
else
{
dropDown = document.getElementById('_ctl0_SecretQuestion');
dropDown.disabled = true;
textBox = document.getElementById('_ctl0_SecretQuestionText');
textBox.disabled = false;
}
}
***************************************************************

The actual names are SecurityStandard, not _ct10_SecurityStandard.

This works fine if I know the actual name of the object.

But in a Datagrid I get something like:

<input id="JobBoardsGrid__ctl2_JobBoard" type="checkbox"
name="JobBoardsGrid:_ctl2:JobBoard" onclick="Javascript:CheckQuestion();" />

and the next row will be:

<input id="JobBoardsGrid__ctl3_JobBoard" type="checkbox"
name="JobBoardsGrid:_ctl3:JobBoard" onclick="Javascript:CheckQuestion();" />

Is there a way to know by what object is calling, what the name is and by
that, I could prepend the extra part to the name of all the other objects in
that DataGridItem?

I am setting up the object to call the function from an AttachScript from
the DataGrid
*******************************************************************
Sub OnAttachScript(sender as Object, e as DataGridItemEventArgs)
if e.Item.ItemType = ListItemType.ITem Or _
e.Item.ItemType = ListItemType.AlternatingItem then
Dim oImageButton as CheckBox = CType(e.Item.FindControl("JobBoard"),
CheckBox)
oImageButton.Attributes.Add ("onClick","Javascript:CheckQuestion();")
end if
end Sub
*******************************************************************************

Thanks,

Tom
 
T

tshad

I figured it out.

***************************************
function CheckJobBoard(me)
{
temp = me.id.replace("_JobBoard","_Override");
override = document.getElementById(temp);
if (me.checked == true)
{
override.disabled = false;
}
else
{
override.disabled = true;
}
******************************************

Called by:

Dim oImageButton as CheckBox = CType(e.Item.FindControl("JobBoard"),
CheckBox)
oImageButton.Attributes.Add ("onClick","Javascript:CheckJobBoard(this);")

The interesting thing I found out was that if I set a checkbox.enabled =
"false" in the code or enable="false" in the <asp:Checkbox... tag, the
javascript will not work.

This is not the case with TextBoxes, however. I can initially set it
(enabled=false) and then change back and forth with javascript.

Not sure why this is the case.

Tom
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top