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