[英]Find ASP.NET WebForms Control and change its ID
嘗試這個
if (e.Row.RowType == DataControlRowType.Header)
{
CheckBox box = (CheckBox)e.Row.FindControl("pendencia_count");
if(box != null)
{
box.ID = "yourid" + e.Row.RowIndex.ToString();
}
}
綁定復選框控件時將其保存到 ViewState 中,並在需要更改其 ID 時從 ViewState 中獲取復選框控件。
protected void grdPendenciasCliente_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
CheckBox cb = (CheckBox)e.Row.FindControl("pendencia_count");
ViewState["CheckBoxPendenciaCount"] = cb;
}
}
:
if (ViewState["CheckBoxPendenciaCount"] != null)
{
CheckBox cb = (CheckBox)ViewState["CheckBoxPendenciaCount"];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.