It is working on button click , becuase i when store the values from datalist into my database , the values got inserted .. but when i am trying to store those value in temporary datatable its not working
[WebMethod]
public static ProductDetails[] DisplayMessage(string name, string price,string obj, string id)
{
string emailid = HttpContext.Current.User.Identity.Name; ;
string date = DateTime.Now.ToString();
string s = HttpContext.Current.User.Identity.Name;
string[] split = s.Split('@');
string username = split[0];
DataTable shop = new DataTable("Table"); // create a dataTable name shop ["Table"] always be same.
// declare the columns name according to your need.
shop.Columns.Add(new DataColumn("prodname", Type.GetType("System.String")));
shop.Columns.Add(new DataColumn("prodprice", Type.GetType("System.Double")));
shop.Columns.Add(new DataColumn("produrl", Type.GetType("System.String")));
shop.Columns.Add(new DataColumn("userid", Type.GetType("System.String")));
shop.Columns.Add(new DataColumn("quantity", Type.GetType("System.Int32")));
shop.Columns.Add(new DataColumn("productid", Type.GetType("System.String")));
shop.Columns.Add(new DataColumn("emailid", Type.GetType("System.String")));
shop.Columns.Add(new DataColumn("username", Type.GetType("System.String")));
shop.Columns.Add(new DataColumn("date", Type.GetType("System.DateTime")));
shop.Columns.Add(new DataColumn("subtotal", Type.GetType("System.Double")));
DataRow new_row;
new_row = shop.NewRow();
new_row["prodname"] = name;
new_row["prodprice"] = price;
new_row["produrl"] = obj ;
new_row["userid"] = UserId;
new_row["quantity"] = 1;
new_row["productid"] = id;
new_row["emailid"] =emailid;
new_row["username"] = username;
new_row["date"] = date;
new_row["subtotal"] = price ;
//add the row to the table
shop.Rows.Add(new_row);
//reload the cart into session
List<ProductDetails> details = new List<ProductDetails>();
foreach (DataRow dtrow in shop.Rows)
{
ProductDetails x = new ProductDetails();
x.prodname = dtrow["prodname"].ToString();
x.quantity = dtrow["quantity"].ToString();
x.subtotal = dtrow["subtotal"].ToString();
details.Add(x);
}
return details.ToArray();
}
public class ProductDetails
{
public string prodname { get; set; }
public string quantity { get; set; }
public string subtotal { get; set; }
}