Wednesday 3 April 2013

Bind and search data in gridview using WCF service

ASPX page


    Json Data
    
    
    

    
    


    

.CS page
  
protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    BindGrid();
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

        private void BindGrid()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("UserId");
            dt.Columns.Add("First Name");
            dt.Columns.Add("Last Name");
            dt.Columns.Add("Company Name");
            dt.Columns.Add("Contact No");
            dt.Columns.Add("Address");
            dt.Columns.Add("Country");
            dt.Rows.Add();
            grdUserData.DataSource = dt;
            grdUserData.DataBind();
            grdUserData.Rows[0].Visible = false;
        }

IWcfService Page
  
namespace MVPProject
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IWcfService" in both code and config file together.
    [ServiceContract(Namespace="MVPProject")]
    public interface IWcfService
    {
        [OperationContract]
        void DoWork();

        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        List GetUserDetails();

        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        List GetSearchUserDetails(string search);

    }
}
WcfService.svc.cs Page
 
namespace MVPProject
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "WcfService" in code, svc and config file together.
    public class WcfService : IWcfService, IViewUserData
    {
        #region Declaration
        PresenterUserData _presenterUserData;
        #endregion

        #region Events

        public void DoWork()
        {
        }

        public WcfService()
        {
            _presenterUserData = new PresenterUserData(this);
        }

        public List GetUserDetails()
        {
            _presenterUserData.GetAllData();
            return UserDatas;
        }

        public List GetSearchUserDetails(string search)
        {
            _presenterUserData.GetAllData();
            if (UserDatas != null && UserDatas.Count > 0)
            {
                UserDatas = UserDatas.Where(x => x.FirstName.ToLower().Contains(search.ToLower()) ||
                    x.LastName.ToLower().Contains(search.ToLower())).ToList();
            }

            return UserDatas;
        }

        #endregion

        #region Members

        public EntityLib.UserData CurrentUserData { get; set; }

        public List UserDatas { get; set; }

        #endregion



    }
}

 

1 comment:

  1. Trade FX At Home On Your PC: exness login Is A Forex Trading Company. The Company States That You Can Make On Average 80 – 300 Pips Per Trade.exness login States That It Is Simple And Easy To Get Started.

    ReplyDelete