string IDX ="";
IDX = Request.QueryString["IDX"];
c_EditItem = (EditItem)Page.LoadControl("ProductBarcodeControls/EditItem.ascx");
c_EditItem.PK_ID = IDX;
this.Web_contaner.Controls.Add(c_EditItem);
c_EditItem.setRunningType(ActionType.UpdatedBarcodeItem);
IDX = Request.QueryString["IDX"];
c_EditItem = (EditItem)Page.LoadControl("ProductBarcodeControls/EditItem.ascx");
c_EditItem.PK_ID = IDX;
this.Web_contaner.Controls.Add(c_EditItem);
c_EditItem.setRunningType(ActionType.UpdatedBarcodeItem);
这里是用户控件中runingType的代码 2
public void setRunningType(string rtype)
{
switch(rtype)
{
case ActionType.UpdatedBarcodeItem:
SetLableToText();
code_txt.EditEnable = false;
Action_pal.Visible = true;
add_btn.Visible = false;
this.BindList();
break;
case ActionType.ViewBarcodeItem:
Action_pal.Visible = false;
this.BindList();
break;
}
}
{
switch(rtype)
{
case ActionType.UpdatedBarcodeItem:
SetLableToText();
code_txt.EditEnable = false;
Action_pal.Visible = true;
add_btn.Visible = false;
this.BindList();
break;
case ActionType.ViewBarcodeItem:
Action_pal.Visible = false;
this.BindList();
break;
}
}
这里是梆定数据的代码 3
DataRow Row = this.myCode.getBarcodeByIDX(this.PK_ID);
code_txt.Text = Row[BarcodeData.Code_FIELD].ToString();
partNo_txt.Text = Row[BarcodeData.PartNo_FIELD].ToString();
UpdatePartNO_txt.Text = Row[BarcodeData.NewPartNo_FIELD].ToString();
StandardPartNO_txt.Text = Row[BarcodeData.StandPartNO_FIELD].ToString();
Customer_txt.Text = Row[BarcodeData.Customer_FIELD].ToString();
status_rdb.SelectedValue = Row[BarcodeData.Status_FIELD].ToString().Trim().ToLower();
remark_txt.Text = Row[BarcodeData.Remark_FIELD].ToString();
LabelType_txt.Text = Row[BarcodeData.LabelType_FIELD].ToString();
LableDescritiop_txt.Text = Row[BarcodeData.LabelDescription_FIELD].ToString();
Description_txt.Text = Row[BarcodeData.Description_FIELD].ToString();
UpdateDesc_txt.Text = Row[BarcodeData.NewDescription_FIELD].ToString();
code_txt.Text = Row[BarcodeData.Code_FIELD].ToString();
partNo_txt.Text = Row[BarcodeData.PartNo_FIELD].ToString();
UpdatePartNO_txt.Text = Row[BarcodeData.NewPartNo_FIELD].ToString();
StandardPartNO_txt.Text = Row[BarcodeData.StandPartNO_FIELD].ToString();
Customer_txt.Text = Row[BarcodeData.Customer_FIELD].ToString();
status_rdb.SelectedValue = Row[BarcodeData.Status_FIELD].ToString().Trim().ToLower();
remark_txt.Text = Row[BarcodeData.Remark_FIELD].ToString();
LabelType_txt.Text = Row[BarcodeData.LabelType_FIELD].ToString();
LableDescritiop_txt.Text = Row[BarcodeData.LabelDescription_FIELD].ToString();
Description_txt.Text = Row[BarcodeData.Description_FIELD].ToString();
UpdateDesc_txt.Text = Row[BarcodeData.NewDescription_FIELD].ToString();
这里是按下update后更新的代码 4
DataRow Row = this.myCode.getBarcodeByIDX(this.PK_ID);
Row[BarcodeData.PartNo_FIELD] = partNo_txt.Text.Trim();
Row[BarcodeData.NewPartNo_FIELD] = UpdatePartNO_txt.Text.Trim();
Row[BarcodeData.StandPartNO_FIELD] = StandardPartNO_txt.Text.Trim();
Row[BarcodeData.Customer_FIELD] = Customer_txt.Text.Trim();
Row[BarcodeData.Status_FIELD] = status_rdb.SelectedValue;
Row[BarcodeData.Remark_FIELD] = remark_txt.Text.Trim();
Row[BarcodeData.LabelType_FIELD] = LabelType_txt.Text.Trim();
Row[BarcodeData.LabelDescription_FIELD] = LableDescritiop_txt.Text.Trim();
Row[BarcodeData.Description_FIELD] = Description_txt.Text.Trim();
Row[BarcodeData.NewDescription_FIELD] = UpdateDesc_txt.Text.Trim();
Row[BarcodeData.LastModify_FIELD] = System.DateTime.Now;
Row.AcceptChanges();
Row[BarcodeData.PartNo_FIELD] = partNo_txt.Text.Trim();
Row[BarcodeData.NewPartNo_FIELD] = UpdatePartNO_txt.Text.Trim();
Row[BarcodeData.StandPartNO_FIELD] = StandardPartNO_txt.Text.Trim();
Row[BarcodeData.Customer_FIELD] = Customer_txt.Text.Trim();
Row[BarcodeData.Status_FIELD] = status_rdb.SelectedValue;
Row[BarcodeData.Remark_FIELD] = remark_txt.Text.Trim();
Row[BarcodeData.LabelType_FIELD] = LabelType_txt.Text.Trim();
Row[BarcodeData.LabelDescription_FIELD] = LableDescritiop_txt.Text.Trim();
Row[BarcodeData.Description_FIELD] = Description_txt.Text.Trim();
Row[BarcodeData.NewDescription_FIELD] = UpdateDesc_txt.Text.Trim();
Row[BarcodeData.LastModify_FIELD] = System.DateTime.Now;
Row.AcceptChanges();
我点击update按钮更新数据的顺序通过跟踪是
1-2-3-4
这里有个逻辑错误:
即 第3步不该执行。
按照我的想法,
数据不会被更新,因为在3步的时候重新绑定了数据。
可是结果相反,数据得到更新。
正常的逻辑应该是
1-2-4
虽然我不知道微软怎么样处理的,我按照正确的逻辑重写了2步
case ActionType.UpdatedBarcodeItem:
SetLableToText();
code_txt.EditEnable = false;
Action_pal.Visible = true;
add_btn.Visible = false;
if(!IsPostBack)
this.BindList();
break;
SetLableToText();
code_txt.EditEnable = false;
Action_pal.Visible = true;
add_btn.Visible = false;
if(!IsPostBack)
this.BindList();
break;