Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code I want to fill gridview from mysql database but if there is no data gridview not fill this is OK..

but I want to error message or warning message this if gridview not fill this personel not registrated yed.

this is my code

XML
string sql = "";
           sql = "SELECT distinct(person)as X,person.personname,person.personsurname FROM `person`,`user`  WHERE personid='" + id+ "' and person.id=user.id";
           MySqlConnection conn = new MySqlConnection(Connect.connStr);
           conn.Open();
           MySqlCommand cmde = new MySqlCommand(sql, conn);
           MySqlDataAdapter xAdapter = new MySqlDataAdapter(cmde);
           DataSet daset = new DataSet();
           xAdapter.Fill(daset);
           GridView1.DataSource = daset;
           if (GridView1.DataSource.ToString() == "" || GridView1.DataSource.ToString() == null || GridView1.DataSource.ToString() == "0")
           {
              
              this person not registered yed I want to give this message

           }
           GridView1.DataBind();
           conn.Close();
Posted
Comments
[no name] 15-Mar-13 7:49am    
Okay so what is the problem? Popup a javascript alert.
Member-2338430 15-Mar-13 7:58am    
if (GridView1.DataSource.ToString() == "" || GridView1.DataSource.ToString() == null || GridView1.DataSource.ToString() == "0")
{

this person not registered yed I want to give this message

}
this part not runnnn
Member-2338430 15-Mar-13 8:07am    
there is no person but this if statement jump GridView1.DataBind();
[no name] 15-Mar-13 9:51am    
If that is your actual problem then why is your question about how to show an error message?

Quite a nice way of displaying errors on the same asp page is to use a ValidationSummary control then add a CustomValidator. Have a look at this link for an example http://justgeeks.blogspot.co.uk/2010/11/adding-item-to-validationsummary.html[^]

An alternative would be to generate a custom error page, but I'm not fond of redirection in these cases
 
Share this answer
 
Try this:
C#
if (GridView1.DataSource.ToString() == "" || GridView1.DataSource.ToString() == null || GridView1.DataSource.ToString() == "0")
{
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "FileRegister", "alert('Notification : User not registered.');", true);
}



--Amit
 
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