我在数据表中填充一个html表,每个数据表行的每个表行都有一个编辑按钮。
我在代码中添加了编辑按钮,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (UserName != null && UserName != "")
{
hUserName.Value = UserName;
}
else
if (hUserName.Value != "")
UserName = hUserName.Value;
ShowTrainingEntry();
ShowUserTraining(); <-------------- this method populates table
hTID.Value = TrainingID.ToString();
}
}
public void ShowUserTraining()
{
....
dTotalTrainingHours += ShowTrainingInPeriod(dv);
....
}
protected decimal ShowTrainingInPeriod(DataView dv)
{
....
foreach (DataRowView rowView in dv)
{
....
Button bEdit = new Button();
int iTID = Convert.ToInt32(dr["ID"].ToString());
bEdit.Text = "Edit";
bEdit.ID = "btnEdit_" + iTID.ToString();
bEdit.CommandName = "Edit";
bEdit.CommandArgument = iTID.ToString();
bEdit.Command += new CommandEventHandler(btnEdit_Click);
....
}
....
}
public void btnEdit_Click(object sender, CommandEventArgs e)
{
clsLog.WriteLog("btnEdit_Click fired.");
clsLog.WriteLog("\t" + e.CommandName);
clsLog.WriteLog("\t" + e.CommandArgument.ToString());
UserName = hUserName.Value;
TrainingID = Convert.ToInt32(e.CommandArgument);
ShowTrainingEntry();
ShowUserTraining();
}
按要求 - HTML表格:
<asp:Table ID="tblMain" runat="server" Width="900" CellPadding="3" CellSpacing="0" CssClass="noborder">
</asp:Table>
btnEdit_Click未被触发(没有日志条目)。
我已经研究了几个小时,我发现唯一一致的事情就是在Page_Load期间必须将事件连接到按钮,我认为这是正确的。
非常感谢任何帮助。
谢谢, 约翰
答案 0 :(得分:0)
尝试做事件登记
btnEdit_Click.Click += new EventHandler(this.btnEdit_Click);