Grid View with null data
-
Hi all, I have a gridview control in asp.net 2.0,and some datas are binding from the database.If there is no data in the databse,then the grid is not displayed.Is it possible to display the grid without any data.The data is added by Thanks Denny
-
Hi all, I have a gridview control in asp.net 2.0,and some datas are binding from the database.If there is no data in the databse,then the grid is not displayed.Is it possible to display the grid without any data.The data is added by Thanks Denny
by assigning a empty datatabel with relevant column name can be useful. eg: DataTable dt = new DataTable(); dt.Columns.Add("dummy"); dt.Rows.Add(); GridView1.DataSource = dt; GridView1.DataBind(); //but this is not a best practise....
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
Hi all, I have a gridview control in asp.net 2.0,and some datas are binding from the database.If there is no data in the databse,then the grid is not displayed.Is it possible to display the grid without any data.The data is added by Thanks Denny
< DataTable source = new DataTable(); gridViewAppointment.DataSource = source; // New empty row is added to the grid view to dis play the data table. source.Rows.Add(source.NewRow()); gridViewAppointment.DataBind(); int columnsCount = gridViewAppointment.Columns.Count; gridViewAppointment.Rows[0].Cells.Clear();// clear all the cells in the row gridViewAppointment.Rows[0].Cells.Add(new TableCell()); //add a new blank cell gridViewAppointment.Rows[0].Cells[0].ColumnSpan = columnsCount; gridViewAppointment.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; gridViewAppointment.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red; gridViewAppointment.Rows[0].Cells[0].Font.Bold = true; // set No Results found to the new added cell gridViewAppointment.Rows[0].Cells[0].Text = "No Appointment Found!"; > yes it is possible but u have to display some message like no recordfound first create the data table bind it with grid view then get column count clear all cells then join all column through colspan then add text