when datagrid is empty?
When my datagrid data is empty i provide a message like No Records Avilable. How can i provide a message?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Lalit MPosted Mar 22, 2010, 2:45 AM
public void BuildNoRecords(DataGrid gridView, DataSet ds, string str)
{
try
{
if (ds.Tables[0].Rows.Count == 0){
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridView.DataSource = ds;
gridView.DataBind();
int columnCount = gridView.Items[0].Cells.Count;gridView.Items[0].Cells.Clear();
gridView.Items[0].Cells.Add(new TableCell());gridView.Items[0].Cells[0].ColumnSpan = columnCount;
gridView.Items[0].Cells[0].Text = str;
gridView.Items[0].Cells[0].CssClass = "TextField";gridView.Items[0].Cells[0].BackColor = System.Drawing.Color.WhiteSmoke;}
}
catch (Exception){
}
}
bind below this inside (!postback)
BuildNoRecords(dg,ds,"No Records found")
ajay rajuPosted Mar 22, 2010, 2:55 AM
i am using datareaders to select the data using ExecuteReader method. In datareaders How i write The code to display a message like
"No Records Found"