c# - Gridview 保存数据会失去旧值
问题描述
我从数据库中获取数据。到下拉列表,如果某些值为空,那么我将其他数据绑定到绑定DropDownList
的行数据中。在按钮上保存GridView
数据时,单击新的选定值仅更新。丢失旧数据值。
一切正常,除了丢失旧数据值
protected override void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateLeaveAssignList();
}
}
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dr = e.Row.DataItem as DataRowView;
shiftMgr = new ShiftManagerBL(BasePage.Provider, BasePage.ConnectionString);
DataTable table = shiftMgr.GetAllShifts(userId);
DropDownList DropDownList51 = (DropDownList)e.Row.FindControl("DropDownList51");
DropDownList DropDownList52 = (DropDownList)e.Row.FindControl("DropDownList52");
if (!string.IsNullOrEmpty(dr["S1"].ToString()))
{
DropDownList51.DataSource = table;
DropDownList51.DataBind();
string a = dr["S1"].ToString();
DropDownList51.SelectedItem.Text = dr["S1"].ToString();
}
else
{
DropDownList51.DataSource = table;
DropDownList51.DataTextField = "shift_title";
DropDownList51.DataValueField = "shift_id";
DropDownList51.DataBind();
}
if (!string.IsNullOrEmpty(dr["S2"].ToString()))
{
DropDownList52.DataSource = table;
DropDownList52.DataBind();
DropDownList52.SelectedItem.Text = dr["S2"].ToString();
}
else
{
DropDownList52.DataSource = table;
DropDownList52.DataTextField = "shift_title";
DropDownList52.DataValueField = "shift_id";
DropDownList52.DataBind();
}
}
}
protected void UpdateAllCustomer(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
Rs.S1 = ((DropDownList)row.FindControl("DropDownList51") as DropDownList).SelectedItem.Value;
Rs.S2 = ((DropDownList)row.FindControl("DropDownList52") as DropDownList).SelectedItem.Value;
}
}
我需要保存旧DropDownList
值以及新更改的值
解决方案
推荐阅读
- notepad++ - 如何为每 10 个逗号替换一个新行
- flutter - 从 SMS Flutter 中读取 OTP
- python - 我需要将所有熊猫行数据保存到 JSON 中的特定字段
- c# - 微软依赖注入。如何将数据获取到构造函数注入的类深几层
- c# - 不使用 IUserType 查询数据库时如何防止 NHibernate SqlDateTime 溢出?
- html - 背景图像渐变淡出
- amazon-web-services - 使 Cloudfront 分发的缓存失效的问题
- angular - 从对象列表中删除重复项
- javascript - 复制一个文件,并重新计算新的状态
- reactjs - 在material-ui Tab容器中实现react hooks useState不起作用