我添加了一个网格视图,数据被绑定到gridview。我在项目模板中放置了一个链接按钮。当我单击此链接按钮时,应该会出现一个弹出窗口。我尝试使用modalPopupExtender但它显示错误:The TargetControlID of 'ModalPopupExtender1' is not valid. A control with ID 'lnkDownload' could not be found
因为linkbutoon在项目模板中找不到它。
<asp:GridView ID="minidata2" CssClass="table" runat="server" AutoGenerateColumns="false" DataKeyNames="abstract">
<Columns>
<asp:BoundField DataField="projectid" HeaderText="MyFileId" />
<asp:BoundField DataField="video" HeaderText="MyFileurl" />
<asp:TemplateField HeaderText="abstract">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="panel1" TargetControlID="lnkDownload" runat="server"></asp:ModalPopupExtender>
现在,当我们点击链接按钮时,如何显示弹出窗口
已更新请检查以下代码
<asp:UpdatePanel runat="server" ID="up1">
<ContentTemplate>
<asp:GridView ID="minidata" CssClass="table" runat="server" AutoGenerateColumns="false" DataKeyNames="abstract">
<Columns>
<asp:BoundField DataField="pid" HeaderText="MyFileId" />
<asp:BoundField DataField="video" HeaderText="MyFileurl" />
<asp:TemplateField HeaderText="abstract">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="panel1" TargetControlID="Button1" runat="server"></asp:ModalPopupExtender>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Panel runat="server" ID="panel1" style="display:none;">
<div>
<asp:Label runat="server" Text="sacca"></asp:Label>
<asp:TextBox runat="server"></asp:TextBox>
<asp:LinkButton runat="server"></asp:LinkButton>
</div>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="minidata" />
</Triggers>
</asp:UpdatePanel>
答案 0 :(得分:0)
ModalPopupExtender1
无法找到gridview内的lnkDownload
因此尝试这样的事情
<asp:GridView ID="minidata2" CssClass="table" runat="server" AutoGenerateColumns="false" DataKeyNames="abstract">
<Columns>
<asp:BoundField DataField="projectid" HeaderText="MyFileId" />
<asp:BoundField DataField="video" HeaderText="MyFileurl" />
<asp:TemplateField HeaderText="abstract">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClientClick='openmodelpopup();' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" Style="display: none;" />
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="panel1" TargetControlID="Button1" runat="server"></asp:ModalPopupExtender>
<script type="text/javascript">
function openmodelpopup() {
document.getElementById('<%=Button1.ClientID %>').click();
}
</script>
答案 1 :(得分:0)
在gridview目标Modalpop之外设置一个按钮或链接按钮。
<asp:GridView ID="minidata2" CssClass="table" runat="server" AutoGenerateColumns="false" DataKeyNames="abstract">
<Columns>
<asp:BoundField DataField="projectid" HeaderText="MyFileId" />
<asp:BoundField DataField="video" HeaderText="MyFileurl" />
<asp:TemplateField HeaderText="abstract">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LinkButton ID="lnkbtn" runat="server"></asp:LinkButton>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="panel1" TargetControlID="lnkbtn" runat="server"></asp:ModalPopupExtender>
然后在链接按钮上点击事件触发gridview显示你的模态弹出窗口:
protected void lnkDownload_Click(object sender, EventArgs e)
{
// your code
ModalPopupExtender1.Show();
}