I have a gridView in asp, currently using the following datasource –
<asp:SqlDataSource ID="SqlDataSourceTEST" runat="server"
ConnectionString="connection string"
SelectCommand="SELECT * FROM table">
</asp:SqlDataSource>
I can adjust the SelectCommand in the code behind by doing –
SqlDataSourceTEST.SelectCommand = "SELECT * FROM table WHERE ID =" + iD;
However I am now adjusting the code to populate the gridView through a web service method –
[WebMethod]
public DataSet sMethod()
{
using (SqlConnection cnn = new SqlConnection(DBcon))
{
string sql = "SELECT * FROM table";
SqlDataAdapter da = new SqlDataAdapter(sql, cnn);
DataSet ds = new DataSet();
da.Fill(ds, "table");
return ds;
}
}
Then on page load populating the gridView –
WebService1 ws = new WebService1();
gridView1.DataSource = ws.sMethod();
gridView1.DataBind();
Is there a way I can adjust the string sql part of the web method in the code behind to add variables?
Make your
WebMethodaccept parameter:and call it from website: