[英]User input is blank in column after updating gridview
After I click update in the grid view, the code works successfully. 在网格视图中单击更新后,代码成功运行。 But when I retrieve the data in another webpage the columns I updated are blank.
但是,当我在另一个网页中检索数据时,我更新的列为空白。 I have no clue why this happens.
我不知道为什么会这样。 Here is the code for both updating and displaying: this is for updating
这是用于更新和显示的代码:这是用于更新
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string v = System.Configuration.ConfigurationManager.ConnectionStrings["harish"].ConnectionString;
con = new OracleConnection(v);
con.Open();
string query = "update leave_module1 set name='"+GridView1.Rows[e.RowIndex].Cells[0].Text+"'";
OracleCommand cmd = new OracleCommand(query, con);
cmd.ExecuteNonQuery();
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('The Data has been added');</script>;");
GridView1.EditIndex = -1;
con.Close();
}
and this the loadgrid() 这是loadgrid()
protected void loadgrid()
{
string v = System.Configuration.ConfigurationManager.ConnectionStrings["harish"].ConnectionString;
con = new OracleConnection(v);
con.Open();
cmd = new OracleCommand("select * from leave_module1 where '"+TextBox1.Text+"' between fd and td", con);
dr = cmd.ExecuteReader();
GridView1.DataSource=dr;
GridView1.DataBind();
con.Close();
dr.Close();
}
You haven't mentioned any where
clause in your update query
, Query should be like this 您没有在
update query
提及任何where
子句,查询应该像这样
Update tableName set ColumnName = 'Value'
where IDcolumn = 1
secondly you should work on Stored procedures instead of this approach. 其次,您应该使用存储过程而不是这种方法。
Blank column record must be because your code ( GridView1.Rows[e.RowIndex].Cells[0].Text
) is providing blank data, you should check it by debugging & watching it's value at runtime. 空列记录必须是因为您的代码(
GridView1.Rows[e.RowIndex].Cells[0].Text
)提供了空数据,您应该通过调试和在运行时观察其值来检查它。
your update statement has no where
clause, so will update all of the rows in the table. 您的update语句没有
where
子句,因此将更新表中的所有行。 That might be what you want, might not. 那可能就是您想要的,也许不是。
your select
statement may also be syntactically flawed. 您的
select
语句可能在语法上也有缺陷。 it would only successfully return rows where there is a column with the name of the value of TextBox1.Text
that contains a value between the value in a column called fd
and the value in a column called td
. 它只会成功返回存在名为
TextBox1.Text
的值的列的行,该行的值介于fd
列的值和td
列的值之间。
These are the might be possible solutions or part of the whole solutions that I think would be helpful: 这些是可能的解决方案,或者是我认为会有所帮助的整个解决方案的一部分:
When the page is post back the values of the gridviews flushed. 页面回发后,gridviews的值将刷新。 If you want to retain the values in Gridview you have to put these values in Viewstate for further operations.
如果要在Gridview中保留值,则必须将这些值放在Viewstate中以进行进一步的操作。 you have to use Viewstate.add() for adding your Gridview values in viewstate before postback.
在回发之前,必须使用Viewstate.add()在viewstate中添加Gridview值。 viewstate.add("key",value);
viewstate.add(“ key”,value);
Hope it helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.