respected sir, i try to learn from your code. first of all thank you very much.
i try like this...
<script type="text/javascript" src="Scripts/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "Default8.aspx/GetCustomers",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
});
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Table");
var row = $("[id*=DataList1] tr:last-child").clone(true);
$("[id*=DataList1] tr").not($("[id*=DataList1] tr:first-child")).remove();
$.each(customers, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("CustomerID").text());
$("td", row).eq(1).html($(this).find("ContactName").text());
$("td", row).eq(2).html($(this).find("City").text());
$("[id*=DataList1]").append(row);
row = $("[id*=DataList1] tr:last-child").clone(false);
});
}
</script>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:Label ID="CustomerID" runat="server" Text="" Font-Bold="true" Font-Size="Medium"/><br />
<asp:Label ID="ContactName" runat="server" Text="" Font-Bold="true" Font-Size="Medium"/><br />
<asp:Label ID="City" runat="server" Text="" Font-Size="12px"/>
<br />
<br />
<hr />
</ItemTemplate>
</asp:DataList>
at .cs page
[WebMethod]
public static string GetCustomers()
{
//string query = "SELECT top 10 CustomerID, ContactName, City FROM Customers";
//SqlCommand cmd = new SqlCommand(query);
//return GetData(cmd).GetXml();
SqlCommand cmd = new SqlCommand("cmdempdetails");
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "cmdempdetails";
return GetData(cmd).GetXml();
}
private static DataSet GetData(SqlCommand cmd)
{
string strConnString = ConfigurationManager.ConnectionStrings["DynamicConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindDummyRow();
}
}
private void BindDummyRow()
{
DataTable dummy = new DataTable();
dummy.Columns.Add("CustomerID");
dummy.Columns.Add("ContactName");
dummy.Columns.Add("City");
dummy.Rows.Add();
DataList1.DataSource = dummy;
DataList1.DataBind();
}
i get value at json. but not properly binding....i think i have problem at
DataTable dummy = new DataTable();
dummy.Columns.Add("CustomerID");
dummy.Columns.Add("ContactName");
dummy.Columns.Add("City");
dummy.Rows.Add();
DataList1.DataSource = dummy;
DataList1.DataBind();
or
var row = $("[id*=DataList1] tr:last-child").clone(true);
$("[id*=DataList1] tr").not($("[id*=DataList1] tr:first-child")).remove();
$.each(customers, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("CustomerID").text());
$("td", row).eq(1).html($(this).find("ContactName").text());
$("td", row).eq(2).html($(this).find("City").text());
$("[id*=DataList1]").append(row);
row = $("[id*=DataList1] tr:last-child").clone(false);
});
i have not understand properly....plz help me.