Chủ đề: Báo lỗi khi định dạng int cho textbox trong repeater [Tiêu đề chung chung. Lỗi gì? Đã có nhiều.]
-
16-09-2011, 07:46 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Báo lỗi khi định dạng int cho textbox trong repeater [Tiêu đề chung chung. Lỗi gì? Đã có nhiều.]
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.
<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>
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;
}
}
View more random threads:
- Cách làm đa ngôn ngữ trong web ASP.NET như thế nào?
- Cách load data lên gridview trong ASP.net (3tire)
- visible 1 button nhưng không được trong asp.net?
- Làm thế nào để lấy giá trị trường ẩn (Visible="False") trong gridview?
- không chép được menu vào sitemap
- Sử dụng các hàm của webservices trong $.ajax như thế nào?
- Làm sao để hiện thị menu được phân quyền
- Xuất DataGridView ra PDF như thế nào?
- Không thể gõ tiếng việt trong Visual Studio khi chạy quyền administrator
- Thắc mắc về dropdowlist
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...