我有很多数据要在GridView中显示。因为每行有太多的信息,所以当用户单击行时,我希望能够显示更多的信息,所以我认为AJAX中的PopupExtender是完美的。
理想情况下,每当选中行中的任何控件时,我都希望弹出窗口显示。我已经成功地将PopupExtender附加到行中的单个控件,但无法将弹出连接到行本身。
我原以为将PopupExtender的TargetControlId设置为RowDataBound事件中的Row's ClientID会有效,但当我这样做时,会得到一个运行时错误:
TargetControlID of 'popupExtId' is not valid.
A control with ID 'gvList_ctl02' could not be found.我注意到GridViewRow是呈现的,tr元素不包含id,所以我还尝试扩展GridView控件以覆盖CreateRow方法来呈现id --使用此方法,我能够呈现行的ID (例如gvList_ctl02),但当我将PopupExtender添加回代码时,也会引发相同的运行时错误。
我还尝试将showPopup() javascript命令绑定到该行的onclick事件,以便手动显示弹出窗口;虽然单击事件已注册为OK,并且确实被触发,但弹出窗口仍未显示。
是否有人知道如何将PopupExtender绑定到GridViewRow?
我的行绑定代码如下:
protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Bind the popup extender's target ID to the row ID
// This will cause a runtime error
PopupControlExtender pop = e.Row.FindControl("popupExtId") as PopupControlExtender;
pop.TargetControlID = e.Row.ClientID;
// Also bind the client side click handler to try to get the popup to show
// The alert is triggered and no javascript error is generated, but the popup does not display
e.Row.Attributes.Add("onclick", "alert('Row Clicked'); $find('" + pop.BehaviorID + "').showPopup();");
}
}非常感谢。
发布于 2010-02-19 20:21:38
如果您不反对使用ajax ModalPopupExtender,我会使用少量的javascript和一些隐藏的按钮单击,从而在网格视图中触发我的模式弹出。我通常将我的模式弹出扩展程序的目标控件标识为我的隐藏按钮,然后,通过javascript,启动我隐藏的按钮的单击事件来显示模式弹出。
这是我的模式弹出和隐藏按钮标记。
<asp:Button ID="hiddenButton" runat="server" Text="" style="display:none"></asp:Button>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender2" runat="server"
TargetControlID="hiddenButton" PopupControlID="Panel1" CancelControlID="CancelButton"
BackgroundCssClass="modalBackground" Drag="True"/>这是我的javascript来显示我的弹出窗口。
function showModal(btnID) {
btn = document.getElementById(btnID);
btn.click();
}在我的行数据库事件中,我从按钮的onclick事件调用javascript函数showModal。
Button myButton = (Button)e.Row.Cells[9].Controls[1];
matchButton.Attributes.Add("onclick", "showModal('" + hiddenButton.ClientID + "');");希望这能帮你找到正确的方向。
https://stackoverflow.com/questions/2299241
复制相似问题