Repeater and CheckBox problem
Hi friends,
I am using a repeater control to bind and list my data from database.
I repeater control there will be a checkbox in header temple and a lable.
I item template there is checkbox and textbox.
Now when ever the header checkbox checked i would like to checked/unchecked all the template items' checkbox.
For that i used javascript and add event "onclick" in page load for headercheck box.
But now i am not able to get repeater control in my javascript.
Here is the code :
function WriteToFile()
{
var ck = document.getElementById('<%=dtrpt.ClientID%>');
var repeater1 = document.getElementById("dtrpt");
alert(ck);
alert(repeater1);
}
IT alert me null.
Now what should i do to get repeater in javascsript.
And how to checked/unchecked all item checkboxs ?
Thanks in advance.
Answers (1)
1
avani ,
you can do thi without Javascript by Simple Foreach Loop
protected void btnCheckAll_Click(object
sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
((CheckBox)item.FindControl("checkbox1")).Checked = true;
}
}
Similarly you can make them uncheck too .. :)
make sure that when you bind the Reapeter at Page_Load()
you code should be in
if ( !IsPostback)
{
}
if my answer helps you then Check Do you like this answer" check box :)