获取repeater中创建的按钮的id,可以通过以下步骤实现:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Button btn = (Button)e.Item.FindControl("btnButton");
btn.ID = "btnButton_" + e.Item.ItemIndex;
}
}
protected void Page_Load(object sender, EventArgs e)
{
foreach (Control control in ContentPlaceHolder1.Controls)
{
if (control is Repeater)
{
Repeater repeater = (Repeater)control;
foreach (RepeaterItem item in repeater.Items)
{
Button btn = (Button)item.FindControl("btnButton_" + item.ItemIndex);
if (btn != null)
{
// 使用获取到的按钮ID进行相应的操作
string buttonId = btn.ID;
// ...
}
}
}
}
}
这样,你就可以通过Repeater中创建的按钮的ID来进行相应的操作了。请注意,代码中的"Repeater1"和"btnButton"是示例名称,你需要根据实际情况修改。
领取专属 10元无门槛券
手把手带您无忧上云