Hi,
What i mentinoed in my previous post is that. You are declaring the dataset in the function " GetContacts", so the dataset is local to it. In the page_load event, when you bid the gridview with the dataset, the dataet doesnt exist. you are also binding it in the function "GetContacts". Either leave that as it is. Or get the function to return the dataset and assign that to the gridview. I have made the change in the code to reflect this. check it out.
you can change your code as follows:
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = GetContacts("Toronto North");
GridView1.DataBind();
}
public dataset GetContacts(string TeamName)
{
//Database Connection stringString sConnection = "server=HTCWEBDEMO;database=hometrust;user id=ht_admin;password=htc_tr!st";SqlConnection htc_SqlConnection = new SqlConnection(sConnection);
htc_SqlConnection.Open();
// Get the Data through the provider.string getContactList_SQLStatement = "SELECT Title,FirstName,LastName,PhoneNumber,Faxnumber, Email FROM ContactList WHERE TeamName='" + TeamName +"'; SELECT FirstName, LastName FROM ContactList WHERE TeamMorty ='True' and TeamName='" + TeamName + "';";
SqlDataAdapter htc_SqlDataAdapter = new SqlDataAdapter(getContactList_SQLStatement, sConnection);DataSet ContactListDataSet = new DataSet();ContactListDataSet.DataSetName = "ContactsList";
htc_SqlDataAdapter.Fill(ContactListDataSet);
ContactListDataSet.Tables[0].TableName = "Contact";
ContactListDataSet.Tables[1].TableName =
"Morty";
// Write data to files: ContactList.xml.
//ContactListDataSet.WriteXml("c:/temp/ContactList.xml");
//return your dataset here or whatever you want to bind your grid with. change the return value of your function accordingly.
return ContactListDataSet;
htc_SqlConnection.Close();
}
pushya.