views:

79

answers:

4

Using C# & asp.net

if there is no data's in the table, gridview displaying one rows (it was empty)

I want to hide the gridview empty row.

How to do this.

+1  A: 

If you are manually data binding than you can check at that time and hide or disable the control if there is no data. If you are data binding using the design view than you should subscribe to the DataBinding or the PreRender events on the control and check then.

Sruly
+1  A: 

you can check if the datatable doesn't have any rows

use:

mydatagrid.DataSource=null;

mydatagrid.DataBind();
Baharanji
+1  A: 

As the other two comments you can either check in code and set MyDataGrid.Visible to true or false to hide the entire table, or you can not bind the datasource, or you can EmptyDataTemplate option to display whatever you want when there is no data for the GridView to display normally.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatemplate.aspx

Moo
+2  A: 

Assuming that you can normally delete that one visible row just check that if a feild that would normally have a value is empty and the row count is 1 then delete that row.

if(String.IsNullOrEmpty(mydatagrid.Rows[0][0].ToString()) && mydatagrid.Rows.Count==1) //Check a field that would normally have a value
{
     mydatagrid.Rows.RemoveAt(0);
}

Let me know if this helps/works

Gage