本文介绍了如何从WeMethod绑定SQLDatasource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我的项目中的WebServis.asmx文件中有WebMethod。我也有asp.net页面,我有文本框,我输入Query的参数,将作为Gridview的数据源。

我想从WebMethod将数据源绑定到Gridview。

我可以这样做或者我需要使用SqlDataReader从我的Query中导出数据吗?



我需要这样的东西:



mkTabl.DataSource = SqlDataSource1;

mkTabl.DataBind();



Webmethod

Hello all . I have WebMethod in WebServis.asmx file in my project . Also i have asp.net 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;
mkTabl.DataBind();

Webmethod

[System.Web.Services.WebMethod]
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"  >
 </asp:GridView>    

推荐答案



这篇关于如何从WeMethod绑定SQLDatasource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:30