如何创建自定义gridview控件?

时间:2021-08-28 01:21:35

Can anyone help me in creating Custom GridView Control in c# .Net?

任何人都可以帮我在c#.Net中创建自定义GridView控件吗?

2 个解决方案

#1


Here's a blog post and a code sample (from one of my projects) that may give you what you need.

这是一篇博客文章和一个代码示例(来自我的一个项目),可以为您提供所需的内容。

ASP.NET 2.0 - Extending GridView control to display extra Footer Rows

ASP.NET 2.0 - 扩展GridView控件以显示额外的页脚行

public class MyGridView : GridView
{
    protected GridViewRow _footerRow = null;

    public override GridViewRow FooterRow
    {
        get
        {
            if (_footerRow == null)
            {
                return base.FooterRow;
            }
            else
            {
                return _footerRow;
            }
        }
    }
    public MyGridView()
    {
    }

    protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
    {
        ...


        ...
    }



    [System.ComponentModel.Category("Behavior")]
    [Themeable(true)]
    [System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.No)]
    public bool ShowHeaderWhenEmpty
    {
        get
        {
            if (this.ViewState["ShowHeaderWhenEmpty"] == null)
            {
                this.ViewState["ShowHeaderWhenEmpty"] = false;
            }

            return (bool)this.ViewState["ShowHeaderWhenEmpty"];
        }
        set
        {
            this.ViewState["ShowHeaderWhenEmpty"] = value;
        }
    }

    [System.ComponentModel.Category("Behavior")]
    [Themeable(true)]
    [System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.No)]
    public bool ShowFooterWhenEmpty
    {
        get
        {
            if (this.ViewState["ShowFooterWhenEmpty"] == null)
            {
                this.ViewState["ShowFooterWhenEmpty"] = false;
            }

            return (bool)this.ViewState["ShowFooterWhenEmpty"];
        }
        set
        {
            this.ViewState["ShowFooterWhenEmpty"] = value;
        }
    }
}

#2


We'd need to know something about what you wanted your GridView to support that isn't possible in the standard one.

我们需要了解您希望GridView支持的内容,这在标准版本中是不可能的。

#1


Here's a blog post and a code sample (from one of my projects) that may give you what you need.

这是一篇博客文章和一个代码示例(来自我的一个项目),可以为您提供所需的内容。

ASP.NET 2.0 - Extending GridView control to display extra Footer Rows

ASP.NET 2.0 - 扩展GridView控件以显示额外的页脚行

public class MyGridView : GridView
{
    protected GridViewRow _footerRow = null;

    public override GridViewRow FooterRow
    {
        get
        {
            if (_footerRow == null)
            {
                return base.FooterRow;
            }
            else
            {
                return _footerRow;
            }
        }
    }
    public MyGridView()
    {
    }

    protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
    {
        ...


        ...
    }



    [System.ComponentModel.Category("Behavior")]
    [Themeable(true)]
    [System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.No)]
    public bool ShowHeaderWhenEmpty
    {
        get
        {
            if (this.ViewState["ShowHeaderWhenEmpty"] == null)
            {
                this.ViewState["ShowHeaderWhenEmpty"] = false;
            }

            return (bool)this.ViewState["ShowHeaderWhenEmpty"];
        }
        set
        {
            this.ViewState["ShowHeaderWhenEmpty"] = value;
        }
    }

    [System.ComponentModel.Category("Behavior")]
    [Themeable(true)]
    [System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.No)]
    public bool ShowFooterWhenEmpty
    {
        get
        {
            if (this.ViewState["ShowFooterWhenEmpty"] == null)
            {
                this.ViewState["ShowFooterWhenEmpty"] = false;
            }

            return (bool)this.ViewState["ShowFooterWhenEmpty"];
        }
        set
        {
            this.ViewState["ShowFooterWhenEmpty"] = value;
        }
    }
}

#2


We'd need to know something about what you wanted your GridView to support that isn't possible in the standard one.

我们需要了解您希望GridView支持的内容,这在标准版本中是不可能的。