Hi Dave,
Thank you for posting.
As for ASP.NET control, if we want to reference and manipulate them in
client-side script code, we should know its client-side ID in the html
document. To get this client-side , we can use the WebControl's ClientID
property. However, we must read it after the certain control has been added
into its parent NamingContainer, otherwise, the ClientID doesn't represent
the actual id that'll be writeout to client html document. Here is a
simple test page which demonstrate on how to use client-side script to
reference sub controls in repeater and use script code to manipulate them:
========aspx==========
<div>
<asp:Repeater ID="Repeater1" runat="server"
OnItemDataBound="Repeater1_ItemDataBound" >
<ItemTemplate>
<br /><hr />
<br />
<asp
ropDownList ID="list1" runat="server">
<asp:ListItem Text="Enable" Value="Enable"></asp:ListItem>
<asp:ListItem Text="Disable" Value="Disable"></asp:ListItem>
</asp
ropDownList>
<asp
ropDownList ID="list2" runat="server">
<asp:ListItem Text="Item1" Value="Item1"></asp:ListItem>
<asp:ListItem Text="Item2" Value="Item2"></asp:ListItem>
<asp:ListItem Text="Item3" Value="Item3"></asp:ListItem>
<asp:ListItem Text="Item4" Value="Item4"></asp:ListItem>
</asp
ropDownList>
</ItemTemplate>
</asp:Repeater>
</div>
============code behind===========
public partial class Repeater_FileList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DirectoryInfo di = new
DirectoryInfo(Server.MapPath("~/Common/"));
FileInfo[] pages = di.GetFiles("*.aspx");
Repeater1.DataSource = pages;
Repeater1.DataBind();
}
string script = @"
function change_list_status(list1id, list2id)
{
var list1 = document.getElementById(list1id);
var list2 = document.getElementById(list2id);
if(list1.selectedIndex == 0)
{
list2.disabled = false;
}else
{
list2.disabled = true;
}
}
";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"list_function", script,true);
}
protected void Repeater1_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DropDownList list1 = e.Item.FindControl("list1") as
DropDownList;
DropDownList list2 = e.Item.FindControl("list2") as
DropDownList;
list1.Attributes["onchange"] = "change_list_status('" +
list1.ClientID + "','" + list2.ClientID + "');";
}
}
}
==============================
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)