[英]textbox value inside a repeater and save
I have a code here that gets a transaction number on a search bar and show it on the page. 我这里有一个代码,可在搜索栏中获取交易号并将其显示在页面上。 I also have 2 textbox wherein the client will enter the price
payed and the OR No of the receipt. 我也有2个文本框,客户可以在其中输入支付的price
和收据的OR号。 However, I am getting an error 但是,我收到一个错误
"Object reference not set to an instance..." “对象引用未设置为实例...”
.ASPX .ASPX
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptrCashierTable" runat="server">
<ItemTemplate>
<div>
<h1 align="center">Transaction Number: <label><%# Eval("TXNNo") %></label>
<h2>Name:<label><%# Eval("FName") %></label>
<label><%# Eval("MName") %></label>
<label><%# Eval("LName") %></label></h2>
<h2>Contact Number: <label><%# Eval("MOBILE") %></label></h2>
<h2>Product Ordered: <label><%# Eval("PName") %></label></h2>
<h2>Product ID:<label><%# Eval("ProductID") %></label></h2>
<h2>Price:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></h2>
<h2>OR No.:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></h2>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="btn_Update" />
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
.CS .CS
public partial class TransactionDetails : System.Web.UI.Page
{
SQLQuery sql = new SQLQuery();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCasierTable();
}
}
private void BindCasierTable()
{
string TransctID = Request.QueryString["TXNNo"];
ds = sql.dsGetClientDetails(TransctID);
rptrCashierTable.DataSource = ds;
rptrCashierTable.DataBind();
}
protected void btn_Update(object sender, EventArgs e)
{
foreach (RepeaterItem item in rptrCashierTable.Items)
{
if (item.ItemType == ListItemType.Item)
{
var txtPrice = item.FindControl("TextBox1") as TextBox;
var txtORNo = item.FindControl("TextBox2") as TextBox;
string TXNNo = Request.QueryString["TXNNo"];
ds = sql.dsAddPayment(txtPrice.Text, txtORNo.Text, TXNNo);
txtPrice.Text = string.Empty;
txtORNo.Text = string.Empty;
BindCasierTable();
}
}
}
}
I am using MSSQL
2008 and stored procedure. 我正在使用MSSQL
2008和存储过程。 I just want to update and put the Price
payed and OR number to their respective field. 我只想更新并将“已付Price
和“或”号放在各自的字段中。
That error message means you are assigning something with null value. 该错误消息表示您正在分配具有空值的内容。 I guess the error pops out here: 我猜错误在这里弹出:
string TransctID = Request.QueryString["TXNNo"]
you should check if its null first: 您应该先检查其null是否为:
if(Request.QueryString["TXNNo"]!=null)
{
// make the assignation here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.