1

我正在尝试在 GridView LinkBut​​ton 上打开一个 ModalPopup,但是当我将 LinkBut​​ton ID 提供给弹出窗口的 targetcontrolid 时,它不接受。请帮我。

<asp:GridView ID="grdView" runat="server" AutoGenerateColumns="False" CellPadding="0"
            ForeColor="#333333" GridLines="None" onrowdatabound="grdView_RowDataBound">
    <Columns>
        <asp:TemplateField HeaderText="Dr. Photo">
            <ItemTemplate>
                <asp:Image ID="Image1" runat="server" Style="height: 80px; width: 100px;" ImageUrl='<%#  String.Format("~/Upload/Docters/" + Eval("ImgName")) %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150px" >
        <ItemStyle Width="150px"></ItemStyle>
        </asp:BoundField>

        <asp:BoundField DataField="Qualification" HeaderText="Qualification"
            ItemStyle-Width="50px" >
        <ItemStyle Width="50px"></ItemStyle>
        </asp:BoundField>
        <asp:TemplateField HeaderText="Click to Contact">
        <ItemTemplate>
        <asp:LinkButton ID="popup" runat="server" Text="Click to Contact"></asp:LinkButton>
        </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

<ajaxToolKit:ModalPopupExtender id="ModalPopupExtender1" runat="server"
    cancelcontrolid="btncancel" okcontrolid="btnSend"
    targetcontrolid="Button1" popupcontrolid="Panel1"
    popupdraghandlecontrolid="PopupHeader" drag="true" backgroundcssclass="ModalPopupBG">
</ajaxToolKit:ModalPopupExtender
4

3 回答 3

6

我正在放置我的代码它会工作

<asp:GridView ID="gvproducts" runat="server" DataKeyNames="sno,"  AutoGenerateColumns="false"  
OnRowCommand="gvproducts_RowCommand" OnPageIndexChanging="gvproducts_PageIndexChanging"
AllowPaging="true" PageSize="10" EmptyDataText="No Record Found" Width="100%"
BorderColor="#BDBDBD" HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" >
<Columns>
 <asp:TemplateField HeaderText="SNo" FooterStyle-HorizontalAlign="Center">
      <ItemTemplate>
            <span>
                <%#Container.DataItemIndex + 1%>
              </span>
        </ItemTemplate>
       </asp:TemplateField>
     <asp:BoundField DataField="indentid" HeaderText="Indent ID"></asp:BoundField>
     <asp:BoundField DataField="productid" HeaderText="Product ID" ></asp:BoundField>
      asp:BoundField DataField="productname" HeaderText="Product Name" ></asp:BoundField>
      <asp:BoundField DataField="quantity" HeaderText="Quantity"  ></asp:BoundField>
      <asp:BoundField DataField="unit" HeaderText="Unit" ></asp:BoundField>
       asp:BoundField DataField="requestby" HeaderText="Request By"></asp:BoundField>
      <asp:TemplateField HeaderText="Purchase" ItemStyle-HorizontalAlign="Center">
         ItemTemplate>
          <asp:LinkButton ID="lnkPurchase" runat="server" CommandName="Purchase" CommandArgument="<%#Container.DataItemIndex%>"
            ext="Purchase" ForeColor="blue">
             </asp:LinkButton>
               </ItemTemplate>
                /asp:TemplateField>
                 </Columns>
                </asp:GridView> 

//模态弹出窗口

<input id="Hid_Sno" type="hidden" name="hddclick" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="MPEPurchase" runat="server" TargetControlID="Hid_Sno"
            PopupControlID="pnlpurchase" RepositionMode="RepositionOnWindowResizeAndScroll"
            BackgroundCssClass="modalBackground" CancelControlID="btnxcancel" PopupDragHandleControlID="pnlpurchase" />

。CS

protected void gvproducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.ToUpper() == "PURCHASE")
    {
        MPEPurchase.Show();
    }
}   
于 2013-09-24T06:43:54.983 回答
0

您必须为此使用 GridView 的 RowDataBound 事件,因为“网格内的任何控件都不能直接访问”。所以你需要在gridview的rowdatabound中找到控件,然后设置Ajaxmodalpopup扩展器的“targetcontrolid”。

于 2013-09-24T06:38:09.543 回答
0

我认为解决这个问题最简单的方法是查看网页生成的 HTML 输出并找出 Button 控件的确切呈现 id。

一旦找到,只需将以下代码中的 id 替换为生成的 id。

<ajaxToolKit:ModalPopupExtender id="ModalPopupExtender1" runat="server"
cancelcontrolid="btncancel" okcontrolid="btnSend"
targetcontrolid="Button1" popupcontrolid="Panel1"
popupdraghandlecontrolid="PopupHeader" drag="true" backgroundcssclass="ModalPopupBG">

大多数时候,asp.net 引擎用自己的 id 替换控件 id。因此,您的
targetcontrolid ="Button1" 可能不会触发。

解决此问题的另一种方法是替换代码如下:

将以下内容替换为:

 targetcontrolid ="Button1"

这个

targetcontrolid ='<%=Button1.ClientID%>'
于 2013-09-24T06:52:43.930 回答