GridView中的自定义标题 [英] Custom Header in GridView

查看:81
本文介绍了GridView中的自定义标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在OnRowCreated方法中的标题行上使用SetRenderMethodDelegate在我的GridView中获得了自定义标题图。虽然我试图将LinkBut​​tons添加到新的标题行,但遇到了问题。

I've already got my custom header drawing in my GridView using SetRenderMethodDelegate on the header row within the OnRowCreated method. I'm having problems trying to add LinkButtons to the new header row though.

这就是RenderMethod的样子:

This is what the RenderMethod looks like:

private void RenderSelectionMode(HtmlTextWriter output, Control container)
{
    TableHeaderCell cell = new TableHeaderCell();
    cell.Attributes["colspan"] = container.Controls.Count.ToString();
    AddSelectionModeContents(cell);
    cell.RenderControl(output);

    output.WriteEndTag("tr");

    HeaderStyle.AddAttributesToRender(output);
    output.WriteBeginTag("tr");

    for(int i = 0; i < container.Controls.Count; i++)
    {
        DataControlFieldHeaderCell cell = (DataControlFieldHeaderCell)container.Controls[i];
        cell.RenderControl(output);
    }
}

private void AddSelectionModeContents(Control parent)
{
    // TODO: should add css classes

    HtmlGenericControl label = new HtmlGenericControl("label");
    label.InnerText = "Select:";

    selectNoneLK = new LinkButton();
    selectNoneLK.ID = "SelectNoneLK";
    selectNoneLK.Text = "None";
    //selectNoneLK.Attributes["href"] = Page.ClientScript.GetPostBackClientHyperlink(selectNoneLK, "");
    //selectNoneLK.Click += SelectNoneLK_Click;
    selectNoneLK.Command += SelectNoneLK_Click;

    selectAllLK = new LinkButton();
    selectAllLK.ID = "SelectAllLK";
    selectAllLK.Text = "All";
    //selectAllLK.Attributes["href"] = Page.ClientScript.GetPostBackClientHyperlink(selectAllLK, "");
    //selectAllLK.Click += SelectAllLK_Click;
    selectAllLK.Command += SelectAllLK_Click;

    parent.Controls.Add(label);
    parent.Controls.Add(selectNoneLK);
    parent.Controls.Add(selectAllLK);
}

正如你所看到的,我尝试了不同的方式让我的LinkBut​​tons工作没有任何工作虽然)。 LinkBut​​tons呈现为普通锚点标记,如下所示:< a id =SelectNoneLK>无< / a>

As you can see, I have tried different ways to get my LinkButtons working (none have worked though). The LinkButtons are rendered as plain anchor tags, like this: <a id="SelectNoneLK">None</a>

我知道事实上这个ID看起来像这样,因为我使用的是母版页,这个ID应该是更长的时间。

I know there is something wrong with the fact that the ID looks like that, since I am using a Master page for this and the ID should be something much longer.

任何帮助将不胜感激!

Nick

推荐答案

我猜测由于cell不是控制层次结构(你永远不会把它添加到表中),LinkBut​​ton永远不会找到一个IContainer父级重写他们的ID。

I'd guess that since cell is not part of the control hierarchy (you never add it to the table), the LinkButton's never find an IContainer parent to rewrite their ID's.

我倾向于用优秀的方式解决这些类型的问题 RenderPipe控件,它允许我在一个位置声明我的控件,但将它们呈现在其他位置。

I tend to solve these types of issues using the excellent RenderPipe control that allows me to declare my controls in one place, but render them somewhere else.

这篇关于GridView中的自定义标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆