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:
- không chép được menu vào sitemap
- Cách upload website wcf lên host?
- Làm thế nào để Cập nhật lại số lượng sau khi thêm sản phẩm?
- Ko chạy lệnh mở file word khi up lên iis
- Lỗi UnobtrusiveValidationMode Khi Tạo Form Đăng Ký
- Publish Project Web App và chạy trên IIS7 với VS2012
- viết css cho menu vertical đa cấp như thế nào?
- Cách load lại trang web theo đúng vùng dữ liệu đang đọc
- Lấy giá trị các control trong PlaceHolder
- thêm,sửa,xóa user dùng asp.net configuration
Vệ sinh cá nhân là một phần quan yếu của sức khỏe nam giới. Dùng dung dịch vệ sinh mỗi ngày mang lại nhiều ích, giúp loại bỏ vi khuẩn và vi sinh vật gây hại, giúp khu vực cơ quan sinh dục luôn sạch...
Gel vệ sinh cu, bạn trai có nên...