How to handle formview and gridview when underlying table is empty?
objectdatasource is used here.
objectdatasource is used here.
private bool LoadDataEmpty
{
get { return (bool)(ViewState["LoadDataEmpty"] ?? false); }
set { ViewState["LoadDataEmpty"] = value; }
}
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
// bubble exceptions before we touch e.ReturnValue
if (e.Exception != null)
{
throw e.Exception;
}
// get the DataTable from the ODS select mothod
DataTable dataTable = (DataTable)((DataSet)e.ReturnValue).Tables[0];
// if rows=0 then add a dummy (null) row and set the LoadDataEmpty flag.
if (dataTable.Rows.Count == 0)
{
DataRow row = dataTable.NewRow();
row[0] = 1;
row[1] = "";
row[2] = "";
row[3] = "";
row[4] = "";
row[5] = DateTime.Now.ToString();
dataTable.Rows.Add(row);
LoadDataEmpty = true;
}
else
{
LoadDataEmpty = false;
}
}
protected void EditGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (LoadDataEmpty && e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Visible = false;
e.Row.Controls.Clear();
}
}


0 Comments:
Post a Comment
<< Home