Click here to Skip to main content
15,793,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all . I have WebMethod in WebServis.asmx file in my project . Also i have page where i have textboxes where i input parameters for Query that will be datasource for Gridview .
I want to bind datasource to Gridview from WebMethod .
Can I make this or i need to use SqlDataReader to export data from my Query ?

I need something like this :

mkTabl.DataSource = SqlDataSource1;

public void CheckCat(string fam, string im , string ot )
  SqlDataSource SqlDataSource1 = new SqlDataSource();
  SqlDataSource1.ID = "SqlDataSource1";
  SqlDataSource1.ConnectionString =         System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  SqlDataSource1.SelectCommand = "SELECT id , org, code FROM Tabl  where (@fam like Tabl.FAM ) or  (@im like Tabl.IM) or ( @ot like Tabl.OT) " ;
  SqlDataSource1.SelectParameters.Add("@fam", fam);
  SqlDataSource1.SelectParameters.Add("@im", im);
  SqlDataSource1.SelectParameters.Add("@ot", ot);

<asp:TextBox ID="FamBox" runat="server" MaxLength="10" /> 
<asp:TextBox ID="ImBox" runat="server" MaxLength="10" /> 
<asp:TextBox ID="OtBox" runat="server" MaxLength="14" />
    <asp:GridView ID="mkTabl" Visible="true"  CssClass="ts1" runat="server" AutoGenerateColumns="False"  PageSize="5" AllowPaging="True" AutoPostBack="True"  >
Updated 10-Nov-15 23:54pm

if you need like below

mkTabl.DataSource = SqlDataSource1;

Change the return type of webmethod from void to Dataset or datatable.

And also after executing the query fill into dataset or datatable inside the webmethod.
Share this answer
What u need to do is to use asp:boundfiels inside asp:gridview to bind data to gridview
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