GridView.FooterRow is Null when custom CreateChildControls

Last post 01-31-2008 7:48 AM by Gaset. 7 replies.

Sort Posts:

  • GridView.FooterRow is Null when custom CreateChildControls

    07-27-2006, 8:05 AM
    • Member
      45 point Member
    • drodrig
    • Member since 05-09-2006, 10:05 AM
    • Spain
    • Posts 9

    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

    David
  • Re: GridView.FooterRow is Null when custom CreateChildControls

    07-29-2006, 7:40 AM
    • Member
      45 point Member
    • drodrig
    • Member since 05-09-2006, 10:05 AM
    • Spain
    • Posts 9

    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;

    }

    }

    David
  • Re: GridView.FooterRow is Null when custom CreateChildControls

    08-12-2006, 3:58 AM
    • Member
      140 point Member
    • cblaze22
    • Member since 03-03-2004, 11:01 AM
    • Posts 28
    I see what is going on in the code, but how do you actually perform the override in the application.  Where would the code go and such?
  • Re: GridView.FooterRow is Null when custom CreateChildControls

    08-22-2006, 11:34 AM
    • Participant
      966 point Participant
    • andrecarrilho
    • Member since 02-06-2006, 12:08 PM
    • Lisboa - Portugal
    • Posts 223

    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

    André da Silva Carrilho
    http://www.acarrilho.com/

    If the post has been answered please marke it as Answered :-)
  • Extended GridView lacks Theme!

    03-06-2007, 3:23 PM
    • Member
      25 point Member
    • aquamoth
    • Member since 08-10-2005, 8:55 AM
    • Enkoping, Sweden
    • Posts 11

    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? 

     

    Filed under:
  • Re: Extended GridView lacks Theme!

    07-20-2007, 12:45 PM

    I'm running into the same theme issue. Any resolution to this in the last 2 years?

  • Re: Extended GridView lacks Theme!

    09-21-2007, 9:27 AM
    • Member
      2 point Member
    • neco
    • Member since 07-04-2007, 1:11 PM
    • Posts 1

    StephenSkinner:

    I'm running into the same theme issue. Any resolution to this in the last 2 years?

     

    You have to write a skin with the tag name of your new control and not use <asp:GridView> skin (for example <uc1:NewGridView> ...)

  • Re: Extended GridView lacks Theme!

    01-31-2008, 7:48 AM
    • Member
      30 point Member
    • Gaset
    • Member since 07-19-2005, 4:22 AM
    • Posts 87

     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.  

Page 1 of 1 (8 items)