When datagrid is empty?
When my datagrid data is empty i provide a message like No Records Avilable. How can i provide a message?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lalit MRank #1,186 · 1.5K reputationPosted Mar 21, 2010, 10:45 PM EDT
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 rajuRank #4,639 · 333 reputationPosted Mar 21, 2010, 10:55 PM EDT
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"