Can anyone help me in creating Custom GridView Control in c# .Net?
A:
We'd need to know something about what you wanted your GridView to support that isn't possible in the standard one.
ChrisF
2009-06-08 11:36:14
I want the gridview to perform sorting and filtering as per the configuration when the data is bound.
2009-06-08 11:50:27
ChrisF
2009-06-08 11:56:38
Am working with VS2008, here i have selected ASP.Net Server Control template to create CustomControl.By default class is inherited from WebControl, how can i inherit the class from GridView control?
2009-06-08 11:59:47
Edit the code to change "WebControl" to "GridVew" as a start.
ChrisF
2009-06-08 12:03:20
Hi, I have to create a CustomGridView control which derives from GridView. I have to write a method which accepts a list(datasource) and the data should be sorted and filtered before doing base.DataBind(). This is what is my requirement, how can i do this?
2009-06-09 05:24:51
+1
A:
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
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;
}
}
}
Tone
2009-06-08 12:22:34