Last post Mar 12, 2015 09:58 PM by Shawn - MSFT
Mar 12, 2015 01:15 AM|vijayrania|LINK
I am practicing of web services file. i created a web method and just called that in default.aspx.cs, but gridview is not showing anything when run.
Code of WebServices.cs
public List<string> getRecords()
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["emp1"].ToString());
SqlCommand com = new SqlCommand("Select * from emp");
Code of default.aspx.cs
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
WebService obj = new WebService();
GridView1.DataSource = obj.getRecords();
please help ....
Mar 12, 2015 01:43 AM|Rajneesh Verma|LINK
You should use SQLDataAdapter and DataTable to get the data using
See working example in below link
Mar 12, 2015 05:04 AM|vijayrania|LINK
Thanks a lot.....
Mar 12, 2015 09:58 PM|Shawn - MSFT|LINK
For this situation, you could try to change the return type into datatable/dataset for your web service method. Also you need change the method body to make sure you retrieve the data from the database and fill in the datatable/dataset.
Then, you could bind your gridview with the method.
You may refer to the following examples for more information: