OK,
Not sure what rLMS.classes.Event is or does, but that shouldn't
matter, for your main issue (I replaced it with a dummy class that has
he same members) or getting the grid to display.
The code here loads a grid on your page. It gets rid of the most of
the module level variables, which you really don't need (and might not
work as you expect on web page) and has divided the code into more
discrete functions, which should make it easier to read, re-use and
debug.
private void Page_Load(Object sender, EventArgs e)
{
short shtSsnClientID;
short shtQryEventID;
shtSsnClientID = Convert.ToInt16(Session["clientID"]);
shtQryEventID =
Convert.ToInt16(Request.QueryString["eid"]);
DataTable Cart = GetCartTable();
//fill cart if empty
if(Cart.Rows.Count == 0)
{
DummyClass cartEvent = new DummyClass();
cartEvent.GetEventByID(shtSsnClientID,shtQryEventID);
AddRowToCart(Cart, 1,
cartEvent.Event_Description,
cartEvent.Event_ListPrice);
}
if (!IsPostBack)
{
BindGrid();
}
}
private DataTable GetCartTable()
{
DataTable Cart = null;
if (Session["rLMS_Cart"] == null)
{
Cart = new DataTable();
Cart.Columns.Add(new
DataColumn("Qty",typeof(Int32)));
Cart.Columns.Add(new
DataColumn("Item",typeof(string)));
Cart.Columns.Add(new
DataColumn("Price",typeof(double)));
}
else
{
Cart = (DataTable)Session["rLMS_Cart"];
}
return Cart;
}
public void dgCart_Edit(Object sender, DataGridCommandEventArgs
e)
{
dgCart.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}
public void dgCart_Cancel(Object
sender,DataGridCommandEventArgs e)
{
dgCart.EditItemIndex = -1;
BindGrid();
}
public void dgCart_Update(Object
sender,DataGridCommandEventArgs e)
{
// For bound columns the edited value is stored in a
textbox,
// and the textbox is the 0th element in the column's
cell
string item = e.Item.Cells[1].Text;
int qty =
Int32.Parse(((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text);
double price = double.Parse(e.Item.Cells[3].Text);
// in-memory DataTable, delete the old row and replace
it with a new one
DataTable Cart = GetCartTable();
if (Cart.Rows.Count > 0)
{
//item exists in cart
Cart.Rows.RemoveAt(0);
}
//add new entry
AddRowToCart(Cart, qty, item, price);
dgCart.EditItemIndex = -1;
BindGrid();
}
private void AddRowToCart(DataTable Cart, int qty, string item,
double price)
{
DataRow dr = Cart.NewRow();
dr[0] = qty;
dr[1] = item;
dr[2] = price;
Cart.Rows.Add(dr);
Session["rLMS_Cart"] = Cart;
}
private void BindGrid()
{
DataView CartView = new DataView(GetCartTable());
CartView.Sort = "Item";
dgCart.DataSource = CartView;
dgCart.DataBind();
}
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/