my aps page:::::
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="trail.aspx.cs" Inherits="practice.Pages.trail" %>
| Customer ID | Customer Name | Mobile No. | Address | Registration Date | |
|---|---|---|---|---|---|
| {{CU.CustomerId}} | {{CU.Name}} | {{CU.Email}} | {{CU.PhoneNumber}} | {{CU.Address}} | {{CU.Date}} |
model class:::
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace practice.Models
{
public class ModelClass
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public string Date { get; set; }
}
}
Controller page
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace practice.Controller
{
[RoutePrefix("NewRoute")]
public class taskController : ApiController
{
public class GetAll: ModelClass
{
}
[Route("getDataForAngularGrid")]
[HttpGet]
public List getDataForAngularGrid(HttpRequestMessage requests)
{
DataTable dt = new DataTable();
List list = new List();
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString());
con.Open();
var query = "select * from SP_getAllData";
SqlCommand com = new SqlCommand(query, con);
//com.CommandType = CommandType.StoredProcedure;
com.ExecuteNonQuery();
con.Close();
SqlDataAdapter adptr = new SqlDataAdapter(com);
adptr.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
GetAll GetAll = new GetAll();
GetAll.CustomerId = Convert.ToInt32(dt.Rows[i]["Customerid"]);
GetAll.Name = dt.Rows[i]["name"].ToString();
GetAll.Address = dt.Rows[i]["address"].ToString();
GetAll.Email = dt.Rows[i]["email"].ToString();
GetAll.PhoneNumber = dt.Rows[i]["phno"].ToString();
GetAll.Date = dt.Rows[i]["date"].ToString();
list.Add(GetAll);
}
}
catch(Exception ex)
{
}
return list;
}
}
}
i copied it from someone on c# corner but i cant understand where he is calling the controller page in asp page.
i wrote the following code in .cs file using gridview tag it is giving me result,but i want the data to be displayed using angular js and web apis
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace practice.Pages
{
public partial class trail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString());
con.Open();
var query = "select * from SP_getAllData";
SqlCommand com = new SqlCommand(query, con);
SqlDataReader sdr = com.ExecuteReader();
//com.CommandType = CommandType.StoredProcedure;
//com.ExecuteNonQuery();
con.Close();
SqlDataAdapter adptr = new SqlDataAdapter(com);
adptr.Fill(dt);
if (dt != null)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
Response.Write("Fail");
}
}
}
}
Manav PandyaPosted Feb 7, 2018, 6:46 AM