我有一个GridView
并且在其SelectedIndexChanged
上触发了代码:
protected void grdEntry_SelectedIndexChanged(object sender, EventArgs e)
{
lblAssignId.Text = grdEntry.SelectedRow.Cells[1].Text == " "
? ""
: grdEntry.SelectedRow.Cells[1].Text;
Ob.BranchId = Globals.BranchID;
Ob.AssignId = lblAssignId.Text;
DataSet dsMain = GetAssignDetails(Ob);
if (dsMain.Tables[0].Rows.Count != 0)
{
// some other code
Task.Factory.StartNew(() => FillMemberShipAndBarCode(dsMain.Tables[0].Rows[0]["CustomerCode"].ToString(), Ob.BranchId));
}
}
填写会员ID的代码是
private void FillMemberShipAndBarCode(string customerCode, string branchId)
{
var sqlCommand = new SqlCommand
{
CommandText = "sp_customermaster",
CommandType = CommandType.StoredProcedure
};
sqlCommand.Parameters.AddWithValue("@CustomerCode", customerCode);
sqlCommand.Parameters.AddWithValue("@BranchId", branchId);
sqlCommand.Parameters.AddWithValue("@Flag", 18);
var data = PrjClass.GetData(sqlCommand);
txtMemberShip.Text = data.Tables[0].Rows[0]["MembershipId"].ToString();
txtBarCode.Text = data.Tables[0].Rows[0]["Barcode"].ToString();
}
它工作正常,但没有更新任何文本框。另外,我在监视窗口中检查,值按预期返回(M-1213
和634-98-4
)并且代码确实到达了这一点txtMemberShip.Text = data.Tables[0].Rows[0]["MembershipId"].ToString();
,但txtMemberShip
只是仍然为空???谁能告诉我为什么不更新文本框?
更新
根据评论,这是页面加载
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropDown();
BindGrid();
SetDefaultsInTextBoxes();
}
}
而且我没有任何等待此任务的代码。