我从数据库获取数据。到下拉列表,如果某些值为空,那么我将绑定行数据的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
值以及新更改的值