Click to See Complete Forum and Search --> : Accessing repeater items on the client


mrbrightside
05-08-2007, 06:26 PM
I posted this in the JavaScript forum but didn're really get any replies. Someone there thought maybe I should post here.

I have a form that contains a data bound repeater. In each item of the repeater I have 4 controls - a checkbox, a radio button, a text box and a drop down list.

I need to be able to disable and enable all of the controls within a specific repeater item. Because the repeater changes the ID attribute of the controls for each item, I decided to insert a new attribute into the controls of each item on the repeater's item databound event and then, in javascript on the client, loop through all of the controls on the form looking for the value in the new attribute I created.

So my code in the databound event looks like this:

Dim sLPM As String = e.Item.DataItem("ListPackMethod_id")

'Add the listpackmethod id to each check box so we can identify it uniquely later...
CType(e.Item.FindControl("checkMethod"), CheckBox).Attributes.Add("ListPackMethod_id", sLPM)
CType(e.Item.FindControl("radioPrimary"), RadioButton).Attributes.Add
("ListPackMethod_id", sLPM)
CType(e.Item.FindControl("textBudget"), TextBox).Attributes.Add("ListPackMethod_id", sLPM)
CType(e.Item.FindControl("ddClass"), DropDownList).Attributes.Add("ListPackMethod_id", sLPM)

Of course, the value of ListPackMethod_id is different for each repeater item. Then, on the onclick event of the checkbox, I fire this client side script:

function CheckBoxHandling()
{
for(i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i]

//This is here for debugging...
window.alert(elm.id + " = " + elm.getAttribute("ListPackMethod_id"));

//This is the real work I want to do when I get it working...
if (elm.getAttribute("ListPackMethod_id") == current.getAttribute("ListPackMethod_id"))
{
elm.enabled = false;

}
}
}

So the problem is, at runtime, the alert window shows that the check box and the radio button attribute values are null while the text box and drop down lists all have the correct values.

But I know that the check box and radio buttons have good values in that attribute because I use them later on in the submit when I am stuffing their values into stored procedure parameters as in the following. This all works perfectly:

methodParams(1).Value() = CType(repeaterPackMethods.Items(nItems).FindControl("checkMethod"), CheckBox).Attributes.Item("ListPackMethod_id").ToString

Any ideas?

Ribeyed
05-09-2007, 12:03 PM
Hi,
are you trying to hide controls in the repeater after the checkbox is checked or you wanting to hide them before?