开发者

c# gridview with lightbox

so im trying to implement a lightbox on a gridview. the lightbox i'm using is the one from here at particle tree

anyway, so basically you need to include a css and rel on your link to make it work. i was able to succesfully include a css class without problems on every cell with TemplateField:

<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>

so that's what i have. mind you, i was just trying it out which one is better, hyperlink or linkbutton so either object i can use as long as i can add a rel attribute on it. this is my code behind.

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");
    }
}

i tried this as well

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

    }
}

but i couldn't include 开发者_运维百科a rel on the second one cuz of vs2010 would give me that red squiggle line.

so, thoughts are much appreciated on how to include a rel on a cell.

thanks much!!!


If you want to add the attribute to each control, when databininding, you can find each control and add the rel attribute directly.

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");
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜