Anh/chị xem dùm em dòng code này sai chỗ nào.Em viết dùng repeater để lưu 1 datatable .Rồi sao đó em tạo button thêm số lượng vào nhưng hiểu sao khi viết code thêm số lượng thì nó báo lỗi:

Object reference not set to an instance of an object.
Đây là phần thiết kế của em:

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table width="100%";>
<tr <th>Chọn</th>
<th>Mã Sản Phẩm</th>
<th>Tên Sản Phẩm</th>
<th>Số Lượng</th>
<th>Đơn Giá</th>
<th>Thành Tiền</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="CheckBox1" runat="server" /></td>
<td><asp:Label runat="server" Text='<%# Eval("idSP") %>'></asp:Label></td>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("Tên Sản Phẩm") %>'></asp:Label></td>
<td><asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Số lượng") %>'></asp:TextBox></td>
<td><asp:Label ID="Label2" runat="server" Text='<%# Eval("Đơn Giá","{0:N}") %>'></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%# Eval("Thành Tiền","{0:N}") %>'></asp:Label></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
<asp:Button ID="btnMua" runat="server" Text="Mua Thêm" CommandName="mua" OnClick="btnMua_Click" />
</td>
<td>
<asp:Button ID="btnXoa" runat="server" Text="Xóa" CommandName="xoa" />
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
Còn đây là phần code:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt = (DataTable)Session["GH"];
Repeater1.DataSource = dt;
Repeater1.DataBind();
if (Session["GH"] == null)
{
Response.Write(" <script type='text/javascript'>alert('Bạn chưa chọn mua sản phẩm nào')</script>");
}
}
}
protected void btnMua_Click(object sender, EventArgs e)
{
CheckBox CheckBox1=sender as CheckBox;
Button btnMua = sender as Button;
TextBox TextBox1 = sender as TextBox;
Label Label2 = sender as Label;
Label Label3 = sender as Label;
int i=1;
i = int.Parse(TextBox1.Text.ToString()) ;--lỗi ở đây:Object reference not set to an instance of an object.
double dg;
double tt;
dg = (double)Convert.ToDouble(Label2.Text);
tt = (double)Convert.ToDouble(Label3.Text);
if (btnMua.CommandName == "mua")
{
tt = i * dg;
}
}
Mấy anh/chị làm ơn sửa dùm.Em cám ơn

View more random threads: