Sir, I am working with asp.net Grid.
My issue is that Grid is not displaying on page load in case of no data in sql Table.
But Grid is showing on page load when i inserted data into table.
can display Grid without data in it?, if can, please send me the code.
Here the code I do:-
public void GridFill()
{
DA = new SqlDataAdapter("select * from tbl_Employee", sqlCon);
dtbl = new DataTable();
DA.Fill(dtbl);
cmdbuilder = new SqlCommandBuilder(DA);
gvEmployee.DataSource = dtbl;
gvEmployee.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridFill();
}
}
Please help me in this topic.
Loading

Iftikar HussainPosted Sep 19, 2013, 1:33 AM
Set the below property for the gridview
Regards,
Iftikar
Iftikar HussainPosted Sep 19, 2013, 2:00 AM
http://geekswithblogs.net/dotNETvinz/archive/2009/03/11/tiptrick-show-header-and-footer-of-gridview-when-no-data.aspx
Regards,
Iftikar
Prasenjit DeyPosted Sep 19, 2013, 1:57 AM
At first use my code, what I have given to you, you will get your answer and prob will be solve
if not satisfied, then check that url:
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html
happy coding
Bineesh ViswanathPosted Sep 19, 2013, 1:55 AM
My data insertion into Grid is through footer textbox and buttons. These lays in footerRow.
So I want to show footer row also when Grid is empty.
Is there any code?, please send.
Bineesh ViswanathPosted Sep 19, 2013, 1:49 AM
Prasenjit DeyPosted Sep 19, 2013, 1:35 AM
protected void BindGridviewData()
{
SqlConnection con = new SqlConnection("Data Source=MYSystem;Initial Catalog=MySamplesDB;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select UserName,FirstName,LastName,Location from UserDetails", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count==0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvdata.DataSource = ds;
gvdata.DataBind();
int columncount = gvdata.Rows[0].Cells.Count;
gvdata.Rows[0].Cells.Clear();
gvdata.Rows[0].Cells.Add(new TableCell());
gvdata.Rows[0].Cells[0].ColumnSpan = columncount;
gvdata.Rows[0].Cells[0].Text = "No Records Found";
}
else
{
gvdata.DataSource = ds;
gvdata.DataBind();
}
con.Close();
}
Carefully copy and replace your variables of this part
if(ds.Tables[0].Rows.Count==0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvdata.DataSource = ds;
gvdata.DataBind();
int columncount = gvdata.Rows[0].Cells.Count;
gvdata.Rows[0].Cells.Clear();
gvdata.Rows[0].Cells.Add(new TableCell());
gvdata.Rows[0].Cells[0].ColumnSpan = columncount;
gvdata.Rows[0].Cells[0].Text = "No Records Found";
}
else
{
gvdata.DataSource = ds;
gvdata.DataBind();
}