我已将一个空的 asp.net 表拖到我的网络表单上。我在这些后面的代码中生成所有行。
现在我的桌子被填满并且有下拉列表。当用户点击保存时,我会浏览所有行并更新数据库中下拉列表中的值。
这一切都很好。但是,如果 2 列各有“Present”,那么这 2 列不应再显示,并且 2 个新列与其他下拉列表一起放置在其位置。
这一切都有效。但是,您必须将整个页面刷新到应该消失的 2 列才能消失。
所以我试图做的是在按钮点击事件结束时。清除整个表,然后重新生成它。但是,当我这样做时,无论出于何种原因,我的值都不再保存到数据库中。
if (IsPostBack == false)
{
// check if dummy variables exist in db- If true just generate tables with values in db. If not generate them.
}
else
{
// grab the values from the database
// generate tables with the values
}
btn click event
{
go through all rows in table(foreach loop)
update each column in the database with cells in each row. while in foreach loop.
//done
}
所以这就是它的运行方式,它的工作原理是预期(所有正确的值都被保存),表只是没有更新给用户。
不工作
if (IsPostBack == false)
{
// same code as above
}
// if postback is true do nothing. By the time it gets to the click event it says there is zero rows in the table so nothing happens.
btn click event
{
// same code
}
也失败。
if (IsPostBack == false)
{
// same code as above
}
else
{
// same code as above but moved into its own method.
gernerateTable();
}
btn click event
{
// update all rows
// once done clear the Tables rows
// call generateTable()
}
最后一个什么都不做,因为出于某种原因它不更新任何东西。我不明白为什么。
那么我在这个生命周期中做错了什么我的过程中的某些东西是错误的。当我希望立即更新表格时,该代码不起作用。