I am having issues with DataTable.
I am trying to create a simple cart but it's not passing all the information to the Cart page when I click Add Cart.
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# ResolveUrl(Eval("Image").ToString()) %>'/>
</div>
<div>
<b>
<asp:Label ID="IDLABEL" runat="server" Text='<%# Eval("jumperID") %>'></asp:Label><br />
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'></asp:Label><br />
<asp:Label ID="TypeLabel" runat="server" Text='<%# Eval("Type") %>'></asp:Label> <br />
</b></div>
<div style="clear: right;">
Our Price: £<%# Eval("Price") %></div>
<asp:TextBox ID="txtQty" runat="server" Text="1" CssClass="QtyTextBox"></asp:TextBox>
<div class="cell1">
<asp:Button ID="btnCart" runat="server" Text="Add to Cart" CommandArgument='<%# Eval("jumperID") %>' OnClick="btnCart_Click"/></div>
When I click the add button it should pass information: jumperid, jumpername, type, quantity and price
However I get the error, and it highlights string JumperName...
"Object Reference not set"
string jumperID = Convert.ToInt32((((Button)sender).CommandArgument)).ToString();
string JumperName = ((Label)listView.FindControl("NameLabel")).Text;
string Type = ((Label)listView.FindControl("TypeLabel")).Text;
string Qty = ((TextBox)listView.FindControl("txtQty")).Text;
if (Session["Cart"] != null)
{
DataTable dt = (DataTable)Session["Cart"];
dt.Rows.Add(jumperID);
dt.Rows.Add(JumperName);
dt.Rows.Add(Type);
dt.Rows.Add(Qty);
Session["Cart"] = dt;
Response.Redirect("MyCart.aspx");
}
else {
DataTable dt = new DataTable();
dt.Columns.Add(("jumperID"),typeof(string));
dt.Rows.Add(jumperID);
dt.Rows.Add(JumperName);
dt.Rows.Add(Type);
dt.Rows.Add(Qty);
Session["Cart"] = dt;
Response.Redirect("MyCart.aspx");
}
Please help me I've been stuck on it for a week now
Aucun commentaire:
Enregistrer un commentaire