我會做這樣的:
編輯:OnClientClick
不會與GridViewRow工作。你可以嘗試以下方法:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" + e.Row.RowIndex);
e.Row.Attributes.Add("onclick", "setVisible('cfilterpopup');__doPostBack('" + GridView1.ClientID + "', 'Select$" + e.Row.RowIndex + "');");
}
說明:在secod行,我們正在改變注入我們setVisible()
方法屬性和調用__doPostBack()
。
編輯2:有兩個問題,現在:
的cfilterpopup
會無形再次呼籲回發。
的Onclick
屬性被消滅了上回發
如何修復#1:
添加標記中的隱藏字段。在setVisible()
裏面設置隱藏字段值爲「1」。在正文onload
上添加一個方法來掃描該值並使該部分可見/不可見。
您使用JavaScript標記可能是這樣的:
<head runat="server">
<title></title>
<script type="text/javascript">
function setVisible(itm) {
document.getElementById('<%=hdnStatus.ClientID %>').value="1";
}
function showcfilterpopup() {
var status = document.getElementById('<%=hdnStatus.ClientID %>').value;
document.getElementById('cfilterpopup').style.visibility = status == "1" ? "visible" : "hidden";
}
</script>
</head>
<body onload="showcfilterpopup();">
<form id="form1" runat="server">
<div>
<div id="cfilterpopup" style="display:none">
<p>cfilterpopup</p>
</div>
<asp:HiddenField ID="hdnStatus" Value="0" runat="server" />
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"></asp:GridView>
</div>
</form>
</body>
</html>
我嘗試的第一個。當我第一次嘗試它時我的錯誤我的語法錯誤。現在點擊它時,它不會設置cfilterpopup Visible,但它會爲GridView設置selectedrow。代碼'e.Row.Attributes.Add(「OnClientClick」,「setVisible('cfilterpopup');」);'即使在我註釋掉另一個時也不起作用。 –
我編輯了我的答案。 'OnClientClick'不適用於GridViewRow。 – afzalulh
太近了。這兩者都執行,但不是我所期望的。 cfilterpopup在瞬間變得可見,然後再次不可見。 –