protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ResetEmpNominee();
}
if (Convert.ToInt32(ddlEmployee.SelectedValue) > 0)
{
populateTrainingInfo(Convert.ToInt16(ddlEmployee.SelectedValue));
}
}
protected void btnTrainingSave_Click(object sender, EventArgs e)
{
try
{
short empID = 0;
if (empID =0)
{
success = hrServer.addToEmpTraining(trainingNew, path);
if (success.Equals("Success"))
{
Msg = "Successfully Added..."; }
else
{
Msg = success;
}
}
else
{
}
WebUtil.jsCall("alert('" + Msg + "')", this);
Page_Load(null, null);
}
catch (Exception ex)
{
WebUtil.MessageBox_Show(ex.Message, this);
}
}
private void populateTrainingInfo(short empID)
{
HumanResourceServer hrServer = new HumanResourceServer();
DataSet trainingInfoes = hrServer.GetEmployeeTrainingInfo(empID);
int i = 0;
int count = trainingInfoes.Tables[0].Rows.Count;
ViewState["TrainingInfo"] = trainingInfoes.Tables[0];
int k = 0;
DataTable dtTraining = trainingInfoes.Tables[0];
for (i = 0; i < dtTraining.Rows.Count; i++)
{
//first row
Table tblTraining = new Table();
tblTraining.Width = 900;
TableCell tcLeft1 = new TableCell();
TableCell tcRight1 = new TableCell();
TableRow tr1 = new TableRow();
tr1.CssClass = "cvItemSubHeader";
Label lblHeader1 = new Label();
lblHeader1.ID = "Training" + Convert.ToString(i + 1);
lblHeader1.Text = "Training :" + Convert.ToString(i + 1);
tcLeft1.CssClass = "cvColumnCaption";
//tcLeft1.CssClass = "cvItemButtonCell";
tcLeft1.Controls.Add(lblHeader1);
tcLeft1.HorizontalAlign = HorizontalAlign.Left;
Button btnTrainingEdit = new Button();
btnTrainingEdit.ID = "btnTrainingEdit" + Convert.ToString(i + 1);
btnTrainingEdit.Text = "Edit";
btnTrainingEdit.CssClass = "DSEButton4";
//Label lblHeader2 = new Label();
//lblHeader2.ID = "LevelofEducationData" + Convert.ToString(i);
//lblHeader2.Text = dtTraining.Rows[i]["EDUCATIONLEVELNAME"].ToString();
tcRight1.HorizontalAlign = HorizontalAlign.Right;
//tcRight1.Style["Padding-left"] ="50";
tcRight1.CssClass = "cvItemButtonCell";
tcRight1.Controls.Add(btnTrainingEdit);
tr1.Cells.Add(tcLeft1);
tr1.Cells.Add(tcRight1);
tblTraining.Rows.Add(tr1);
btnTrainingEdit.Click += new System.EventHandler(btnTrainingEdit_click);
tcRight1.Controls.Add(btnTrainingEdit);
tr1.Cells.Add(tcLeft1);
tr1.Cells.Add(tcRight1);
tblTraining.Rows.Add(tr1);
//hidden row for educationid
tcLeft1 = new TableCell();
tcRight1 = new TableCell();
tr1 = new TableRow();
tr1.CssClass = "hiddenDynamicRows";
lblHeader1 = new Label();
lblHeader1.ID = "TRAININGID" + Convert.ToString(i + 1);
lblHeader1.Text = "TRAININGID";
tcLeft1.CssClass = "cvColumnCaption";
tcLeft1.Controls.Add(lblHeader1);
tcLeft1.HorizontalAlign = HorizontalAlign.Left;
Label lblHeader2 = new Label();
lblHeader2.ID = "TRAININGIDData" + Convert.ToString(i + 1);
lblHeader2.Text = dtTraining.Rows[i]["TRAININGID"].ToString();
tcRight1.Controls.Add(lblHeader2);
tr1.Cells.Add(tcLeft1);
tr1.Cells.Add(tcRight1);
tblTraining.Rows.Add(tr1);
Trainings.Controls.Add(tblTraining);
}
count = trainingInfoes.Tables[0].Rows.Count;
}
aspx页面包含以下代码
<table class="contentRow" width="900px">
<tr class="cvItemHeader" align="left">
<td align="left" >
<div><div class="cvItemHeaderText"> Training Summary </div>
<div class="cvItemHeaderButton">
<asp:Button ID="btnAddTraining" runat="server" CssClass="DSEButton4"
Text="Add" onclick="btnAddTrainingInfo_Click" /> </div>
</div>
</td>
</tr>
<div id="Trainings" runat="server"></div>
</table>
抱歉,我的问题不明确。 btnTrainingSave_Click方法将数据保存到数据库中。我需要使用id =&#39; Trainings&#39;来更新div。将数据保存到数据库后。我在btnTrainingSave_Click方法的末尾调用了page_load方法。但它不起作用。任何人都可以帮助我,我该怎么办?也许这次我的问题很明确。
答案 0 :(得分:0)
概念错误,刷新页面重定向到同一个网址
Page.Response.Redirect(Page.Request.Url.ToString(), true);