protected
GridViewRow _footerRow2;
public
override GridViewRow FooterRow
{
get
{
GridViewRow f =
base.FooterRow;
if (f !=
null)
return f;
else
return _footerRow2;
}
}
protected
GridViewRow _headerRow2;
public
override GridViewRow HeaderRow
{
get
{
GridViewRow h =
base.HeaderRow;
if (h !=
null)
return h;
else
return
this._headerRow2;
}
protected
override int CreateChildControls(System.Collections.IEnumerable dataSource,
bool dataBinding)
{
int numRows =
base.CreateChildControls(dataSource, dataBinding);
//no data rows created, create empty table if enabled
if (numRows == 0 && ShowEmptyTable)
{
//create table
Table table =
new Table();
table.ID =
this.ID;
//convert the exisiting columns into an array and initialize
DataControlField[] fields =
new DataControlField[this.Columns.Count];
this.Columns.CopyTo(fields, 0);
if (this.ShowHeader)
This looks like a great way to extend the gridview control.
However, as soon as I extend the GridView, the StyleSheetTheme doesn't kick in.
To make sure, I tried to extend the GridView without adding ANY code (no overrides, no new properties, nothing). The theme disappears for my custom control anyway, but it works fine for other gridviews on the same page!
I currently have a problem with disabling header (or some controls in header) when grid is empty. Actual behavior is that, when grid is empty, setting HeaderRow.Enabled to false does not disable it on first post-back, but only on the second. I cannot figure
out what the problem is.
drodrig
Member
45 Points
9 Posts
GridView.FooterRow is Null when custom CreateChildControls
Jul 27, 2006 12:05 PM|LINK
Hi all, im tryng to have a GridView that suppoorts empty datasource, and INSERT functionallity at FooterRow.
I have my own class derived from GridView withfollowing code:
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
{
int numRows = base.CreateChildControls(dataSource, dataBinding);
//no data rows created, create empty table if enabled
if (numRows == 0 && ShowEmptyTable)
{
//create table
Table table = new Table();
table.ID = this.ID;
//create a new header row
GridViewRow row = base.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
//convert the exisiting columns into an array and initialize
DataControlField[] fields = new DataControlField[this.Columns.Count];
this.Columns.CopyTo(fields, 0);
this.InitializeRow(row, fields);
table.Rows.Add(row);
//create the empty row
row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.ColumnSpan = this.Columns.Count;
cell.Width = Unit.Percentage(100);
cell.Controls.Add(new LiteralControl(EmptyTableRowText));
row.Cells.Add(cell);
table.Rows.Add(row);
if (this.ShowFooter)
{
//create a new footer row
GridViewRow rowFooter = base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
//convert the exisiting columns into an array and initialize
DataControlField[] fieldsFooter = new DataControlField[this.Columns.Count];
this.Columns.CopyTo(fieldsFooter, 0);
this.InitializeRow(rowFooter, fieldsFooter);
table.Rows.Add(rowFooter);
}
this.Controls.Add(table);
GridViewRow testFooter=this.FooterRow; //This is for testing that Footer is NULL
}
return numRows;
}
When I press a Buttom in page, I have this code:
DropDownList DeviceID = (DropDownList)GridViewAmbientActions.FooterRow.FindControl("DropDownListDevicesAdd");But the result is that FooterRow is null.
Any idea why?
Thank you
drodrig
Member
45 Points
9 Posts
Re: GridView.FooterRow is Null when custom CreateChildControls
Jul 29, 2006 11:40 AM|LINK
Here is the solution thanks to CISCBrain
protected GridViewRow _footerRow2; public override GridViewRow FooterRow{
get{
GridViewRow f = base.FooterRow; if (f != null) return f; else return _footerRow2;}
}
protected GridViewRow _headerRow2; public override GridViewRow HeaderRow{
get{
GridViewRow h = base.HeaderRow; if (h != null) return h; else return this._headerRow2;}
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding){
int numRows = base.CreateChildControls(dataSource, dataBinding); //no data rows created, create empty table if enabled if (numRows == 0 && ShowEmptyTable){
//create table Table table = new Table();table.ID =
this.ID; //convert the exisiting columns into an array and initialize DataControlField[] fields = new DataControlField[this.Columns.Count]; this.Columns.CopyTo(fields, 0); if (this.ShowHeader){
//create a new header row_headerRow2 =
base.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal); this.InitializeRow(_headerRow2, fields);table.Rows.Add(_headerRow2);
}
//create the empty row GridViewRow emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); TableCell cell = new TableCell();cell.ColumnSpan =
this.Columns.Count;cell.Width =
Unit.Percentage(100); if (!String.IsNullOrEmpty(EmptyDataText))cell.Controls.Add(
new LiteralControl(EmptyDataText)); if (this.EmptyDataTemplate != null)EmptyDataTemplate.InstantiateIn(cell);
emptyRow.Cells.Add(cell);
table.Rows.Add(emptyRow);
if (this.ShowFooter){
//create footer row_footerRow2 =
base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal); this.InitializeRow(_footerRow2, fields);table.Rows.Add(_footerRow2);
}
this.Controls.Clear(); this.Controls.Add(table);}
return numRows;}
}
cblaze22
Member
140 Points
28 Posts
Re: GridView.FooterRow is Null when custom CreateChildControls
Aug 12, 2006 07:58 AM|LINK
andrecarrilh...
Participant
966 Points
223 Posts
Re: GridView.FooterRow is Null when custom CreateChildControls
Aug 22, 2006 03:34 PM|LINK
Hi
How can I use the code u posted? Where to a put it and how do a set it to show the header and footer in my custom GridView?
Cheers
http://www.acarrilho.com/
If the post has been answered please marke it as Answered :-)
aquamoth
Member
25 Points
11 Posts
Extended GridView lacks Theme!
Mar 06, 2007 07:23 PM|LINK
This looks like a great way to extend the gridview control.
However, as soon as I extend the GridView, the StyleSheetTheme doesn't kick in.
To make sure, I tried to extend the GridView without adding ANY code (no overrides, no new properties, nothing). The theme disappears for my custom control anyway, but it works fine for other gridviews on the same page!
Any idea's why?
GridView Themes
StephenSkinn...
Member
4 Points
8 Posts
Re: Extended GridView lacks Theme!
Jul 20, 2007 04:45 PM|LINK
I'm running into the same theme issue. Any resolution to this in the last 2 years?
neco
Member
2 Points
1 Post
Re: Extended GridView lacks Theme!
Sep 21, 2007 01:27 PM|LINK
You have to write a skin with the tag name of your new control and not use <asp:GridView> skin (for example <uc1:NewGridView> ...)
Gaset
Member
30 Points
87 Posts
Re: Extended GridView lacks Theme!
Jan 31, 2008 11:48 AM|LINK
Hi,
I currently have a problem with disabling header (or some controls in header) when grid is empty. Actual behavior is that, when grid is empty, setting HeaderRow.Enabled to false does not disable it on first post-back, but only on the second. I cannot figure out what the problem is.