我在gridview的模板中有一個panel控件。
我需要在javascript函數中隱藏/取消隱藏面板,爲此我需要將面板的ID傳遞給javascript。在gridview中爲panel控件設置id
問題是所有面板在gridview中都有相同的ID,所以我需要爲每個面板設置唯一的ID。
我試圖做的:
<asp:Panel id= "Panel_<%# Eval("ID")%>"
和其他一些變化,但總是得到一個錯誤。
面板包含其他一些控件,我需要它是服務器端,因爲我需要設置爲隱藏代碼(如果用戶進行身份驗證檢查後)
我能做些什麼?
p.s.
它不必是Panel,我可以使用Findcontrol找到的任何其他控件,並且可以保存其他控件。
更新:
I set the the js event in code behind:
protected void gvw_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (UserIsAuthenticated)
{
HyperLink title = e.Row.FindControl("lnkTitle") as HyperLink;
Panel panel = e.Row.FindControl("panel") as Panel;
title.Attributes.Add("onmouseover", "ShowHidePanel(" + panel.ClientID +")");
//All get the same id!!!
}
}
}
如果你在gridview中這樣做,那麼你最終會得到N'hidePanel()'函數。 – M4N 2010-03-15 22:44:51
@Martin你是對的。更新爲具有N個'hidePanel()'調用。 – Li0liQ 2010-03-15 23:10:15