【问题标题】:c# gridview with lightbox时间:2019-05-10 标签:c#gridview with lightbox
【发布时间】:2011-03-22 14:28:51
【问题描述】:

所以我试图在 gridview 上实现一个灯箱。我使用的灯箱来自 here at particle tree

无论如何,所以基本上你需要在你的链接上包含一个 css 和 rel 以使其工作。我能够成功地使用 TemplateField 在每个单元格上包含一个 css 类,而不会出现问题:

<asp:TemplateField HeaderText="Set of Links">
                    <ItemTemplate>
                        <asp:HyperLink ID="hyplink" runat="server" Text='<%#Eval("Link") %>' CssClass="lbAction" NavigateUrl="tolink.aspx?ruleset={0}"></asp:HyperLink>

                        <asp:LinkButton ID="link" runat="server" Text='<%#Eval("Link") %>'>LinkButton</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

这就是我所拥有的。请注意,我只是在尝试哪个更好,超链接或链接按钮,因此只要我可以在其上添加 rel 属性,我就可以使用任何一个对象。 这是我的代码。

void theGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Cells[0].CssClass = "lbAction";
        e.Row.Cells[0].Attributes.Add("rel", "insert");
    }
}

我也试过了

protected void theGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.CssClass = "lbAction";

    }
}

但我不能在 vs2010 的第二个中包含 rel,因为它会给我那个红色的曲线。

因此,非常感谢有关如何在单元格中包含 rel 的想法。

非常感谢!!!

【问题讨论】:

  • 您是否尝试将 rel 属性添加到行或单元格中的每个控件(HyperLink 和 LinkBut​​ton)?
  • 每个控件。基本上是超链接列上的每个单元格。

标签: c# javascript jquery asp.net gridview


【解决方案1】:

如果要给每个控件添加属性,在数据绑定的时候,可以找到每个控件,直接添加rel属性。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      HyperLink hpl = (HyperLink)e.Row.Cells[0].FindControl("hyplink");
      hpl.Attributes.Add("rel", "insert");
      LinkButton lkb = (LinkButton)e.Row.Cells[0].FindControl("link");
      lkb.Attributes.Add("rel", "insert");
   }
}

【讨论】:

  • 对我有用。运行上述代码时,在每个控件添加属性后设置断点,查看是否有新添加的属性。
  • 我知道出了什么问题,我忘了在我的 gridview 上添加 onrowdatabound。工作得很好!谢谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-21
  • 2012-07-29
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
  • 2020-10-01
  • 2015-06-14
相关资源
最近更新 更多