[英]Asp.net Listview does not bind after performing insert operation
I have listview control in my page. 我的页面中有listview控件。 I gets populated onPage load as well as when new record entered in the table. 我将填充onPage加载以及在表中输入新记录时的填充。 Problem is after performing InsertOperation I am calling It's bind method again but it doesn't refresh its data. 问题是执行InsertOperation之后,我再次调用它的bind方法,但是它不刷新其数据。 Hence I debugged it & executed actual query in SQL & query returns with added rows. 因此,我调试了它并在SQL中执行了实际查询,并返回了添加行的查询返回。
protected void insertBulkPricing()
{
try {
MySqlConnection con = new MySqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings("conio2").ConnectionString();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "INSERT INTO bulk_pricing (productID, rangeFrom, rangeTo, price, time, discount, status) VALUES(@productID, @rangeFrom, @rangeTo, @price, @time, @discount, @status)";
cmd.Parameters.AddWithValue("@productID", productID.Text);
cmd.Parameters.AddWithValue("@rangeFrom", bulkRangeFrom.Text);
cmd.Parameters.AddWithValue("@rangeTo", bulkRangeTo.Text);
cmd.Parameters.AddWithValue("@price", bulkPrice.Text);
cmd.Parameters.AddWithValue("@time", bulkTime.Text);
cmd.Parameters.AddWithValue("@discount", bulkDiscount);
cmd.Parameters.AddWithValue("@status", "active");
cmd.Connection = con;
con.Open();
this.bindBulkPricing();
cmd.ExecuteNonQuery();
con.Close();
} catch (Exception ex) {
Response.Write(ex);
}
}
private void bindBulkPricing()
{
string action = Request.QueryString("action").ToString;
if (action == "new") {
productID.Text = rowNumber;
}
try {
string str = "select * from bulk_pricing where productID = @productID";
string conString = ConfigurationManager.ConnectionStrings("conio2").ConnectionString;
MySqlConnection con = new MySqlConnection(conString);
MySqlCommand cmd = new MySqlCommand(str);
cmd.Parameters.AddWithValue("@productID", productID.Text);
con.Open();
MySqlDataAdapter da = new MySqlDataAdapter();
cmd.Connection = con;
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
bulkPriceList.DataSource = dt;
bulkPriceList.DataBind();
con.Close();
} catch (Exception ex) {
Response.Write(ex);
}
}
protected void insertBulkPricing()
{
try {
MySqlConnection con = new MySqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings("conio2").ConnectionString();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "INSERT INTO bulk_pricing (productID, rangeFrom, rangeTo, price, time, discount, status) VALUES(@productID, @rangeFrom, @rangeTo, @price, @time, @discount, @status)";
cmd.Parameters.AddWithValue("@productID", productID.Text);
cmd.Parameters.AddWithValue("@rangeFrom", bulkRangeFrom.Text);
cmd.Parameters.AddWithValue("@rangeTo", bulkRangeTo.Text);
cmd.Parameters.AddWithValue("@price", bulkPrice.Text);
cmd.Parameters.AddWithValue("@time", bulkTime.Text);
cmd.Parameters.AddWithValue("@discount", bulkDiscount);
cmd.Parameters.AddWithValue("@status", "active");
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
this.bindBulkPricing();
} catch (Exception ex) {
Response.Write(ex);
}
}
You only run cmd.ExecuteNonQuery()
after run this.bindBulkPricing()
. 您只能在运行cmd.ExecuteNonQuery()
之后运行this.bindBulkPricing()
。 I hope it will work for you. 希望它对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.