Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
.aspx code

ASP.NET
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="false" ShowHeaderWhenEmpty="true" EmptyDataText="No records Found">
    
    </asp:GridView>



.cs code

C#
public partial class Pending : System.Web.UI.Page
   {
       SqlConnection con = new SqlConnection("Data Source=jayraj-pc\\sqlexpress;Initial Catalog=Internship;Integrated Security=True;Pooling=False");

       protected void Page_Load(object sender, EventArgs e)
       {
           BindGridviewData();

       }

       protected void BindGridviewData()
   {
       con.Open();
           string p = "Pending";

           SqlCommand cmd = new SqlCommand("select FirstName,LastName,LocationPreference,College,Status,null as 'Action',null as 'Actions',UserID,InternshipID from UsersApplied where InternshipID='" + Request.QueryString["InternshipID"].ToString() + "' and  Status='" + p + "'", con);

           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataSet ds = new DataSet();
           da.Fill(ds);
           //DataTable dt = new DataTable();
           //da.Fill(dt);
          // if (dt.Rows.Count > 0)
           if (ds.Tables[0].Rows.Count == 0)
           {
               ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
               GridView1.DataSource = ds;
               GridView1.DataBind();
               int columncount = GridView1.Rows[0].Cells.Count;
               GridView1.Rows[0].Cells.Clear();
               GridView1.Rows[0].Cells.Add(new TableCell());
               GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
               GridView1.Rows[0].Cells[0].Text = "No Records Found";



               //GridView1.DataSource = dt;
               //GridView1.DataBind();


               //Pending();




           }
           else
           {
               GridView1.DataSource = ds;
               GridView1.DataBind();
           }
           con.Close();
   }
Posted
Comments
Bh@gyesh 22-Apr-14 6:18am    
Check your dataset. it should not be NULL.

1 solution

I think you want show the empty Grid(one blank row with status text), here couple of solutions

GridView - Show headers on empty data source[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900