0

我希望将悬停菜单弹出到从数据源动态填充的网格视图的行。我尝试在发生 rowdatabound 事件时将 hovermenuextender 控件的 TargetcontrolId 属性设置为行唯一 ID。但是弹出窗口不是出现在每一行的右侧,而是出现在标题行的右侧。有人可以帮我解决这个问题吗?我使用下面的代码相同

代码隐藏:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    try
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HoverMenuExtender hoverMenu =(HoverMenuExtender)e.Row.FindControl("hme2");
            if (hoverMenu != null)
            {
                hoverMenu.TargetControlID = hoverMenu.Parent.Parent.UniqueID;

            } 
        }
    }
}

页面:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" ShowFooter="false" ShowHeader="false"
      OnRowEditing="GridView1_RowEditing" OnRowCommand="GridView1_RowCommand" OnRowUpdating="GridView1_RowUpdating"
      GridLines="None"  OnRowDataBound="GridView1_RowDataBound">

      <AlternatingRowStyle BackColor="White" />
      <Columns>
        <asp:TemplateField HeaderText ="Talk Title">
          <ItemTemplate>
            <asp:Label Font-Bold="true" ID="lbltalktitle"  runat="server" Text='<%#Eval("Talk_Title") %>' />
          </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText ="Brand">
          <ItemTemplate>
            <asp:Label ID="lblBrand" runat="server" Text='<%# Eval("Brand") %>' /></td>
          </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText ="Franchise">
          <ItemTemplate>
            <asp:Label ID="lblFranchise" runat="server" Text='<%# Eval("Franchise") %>' />
          </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText ="programmetype">
          <ItemTemplate>
            <asp:Label ID="lblprg" runat="server" Text='<%# Eval("programmetype") %>' />
          </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText ="programmetype">
          <ItemTemplate>
            <asp:Label ID="lblsaledforce" runat="server" Text='<%# Eval("salesforce") %>' />
          </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText ="Start_Date">
          <ItemTemplate>
            <asp:Label ID="lblstartdate" runat="server" Text='<%# Eval("Start_Date") %>' />
          </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText ="End_Date">
          <ItemTemplate>
            <asp:Label ID="lblenddate" runat="server" Text='<%# Eval("End_Date") %>' />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
          <ItemTemplate>
            <cc1:HoverMenuExtender ID="hme2" runat="server" TargetControlID="lblenddate"
              PopupControlID="PopupMenuX" HoverCssClass="popupHover" PopupPosition="Right"/>

            <asp:Panel CssClass="popupMenu" ID="PopupMenuX" runat="server">
              <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" /><br />
              <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete" />
            </asp:Panel>
          </ItemTemplate>
        </asp:TemplateField>

      </Columns>

      <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
      <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
      <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
      <RowStyle  ForeColor="Black"  />
      <SortedAscendingCellStyle BackColor="#F1F1F1" /> 
      <SortedAscendingHeaderStyle BackColor="#594B9C" />
      <SortedDescendingCellStyle BackColor="#CAC9C9" />
      <SortedDescendingHeaderStyle BackColor="#33276A" />
    </asp:GridView>
4

1 回答 1

0
protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        AjaxControlToolkit.HoverMenuExtender ajxhovermenu = (AjaxControlToolkit.HoverMenuExtender)e.Row.FindControl("ahm_1");
        e.Row.ID = e.Row.RowIndex.ToString();
        ajxhovermenu.TargetControlID = e.Row.ID;
    }
}

Give TargetControlID of the HoverMenuExtender in RowCreated event of GridView and set it as the RowID

于 2012-08-30T09:51:26.347 回答