Button add code :
protected void btnAdd_Click(object sender, ImageClickEventArgs e)
{
try
{
AddToOrder();
}
catch
{
string Msg = "<script>alert('Error occurred during adding the product..!');</script>";
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", Msg, false);
}
}
public void AddToOrder()
{
OrdersDataContext context = DataContextSingleton.Instance;
_order = new Order();
_order.quantity= Convert.ToInt32(dropdownlist.SelectedItem.Value);
_order.price = Convert.ToInt32(dropdownlist2.SelectedItem.Value);
_order.note = TextBox4.Text;
context.Orders.InsertOnSubmit(order);
context.SubmitChanges();
this.RefreshGrid();
}
public void RefreshGrid()
{
OrdersDataContext contex = DataContextSingleton.Instance;
var query = (from o in _context.Orders
select new
{
Quantity = o.quant,
Price = o.price,
notes= o.note
});
OrderGridView.DataSource = query.ToList();
OrderGridView.DataBind();
}
I hope this could help you!