我有一个用于更新记录的FormView。有一个链接按钮,当发生火灾时,应通过BLL和DAL进行更新。我没有使用内置的ODS,我也不会考虑使用它。
我通过调用从数据库中获取数据的方法,手动填充了所有网格和表单。
例如,我的详细信息视图填充如下:
protected void DlMembers_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.ToString() == "Select")
{
DlMembers.Visible = false;
lblError.Text = string.Empty;
lblError.Visible = false;
fvMemberDetail.Visible = true;
fvMemberDetail.ChangeMode(FormViewMode.Edit);
MemberBLL getMemberInfo = new MemberBLL();
int Ident = Convert.ToInt32(e.CommandArgument.ToString());
fvMemberDetail.DataSource = getMemberInfo.GetMemberByIdent(Ident);
fvMemberDetail.DataBind();
}
if (e.CommandName.ToString() == "DeleteSelected")
{
DlMembers.Visible = true;
lblError.Text = string.Empty;
lblError.Visible = false;
fvMemberDetail.Visible = false;
fvMemberDetail.ChangeMode(FormViewMode.ReadOnly);
}
如果要在click事件上设置我的链接按钮并执行此操作(除了运行时永远不会达到此方法),我想做什么:
protected void MemberInfoUpdating(object sender, EventArgs e)
{
TextBox id = (TextBox)fvMemberDetail.FindControl("txtIdent");
if (id.Text != string.Empty || id.Text != "")
{
TextBox txtFN = (TextBox)fvMemberDetail.FindControl("txtFN");
TextBox txtLN = (TextBox)fvMemberDetail.FindControl("txtLN");
DropDownList ddlAddress = (DropDownList)fvMemberDetail.FindControl("ddlAddress");
TextBox txtEmail = (TextBox)fvMemberDetail.FindControl("txtEmail");
TextBox txtHPhone = (TextBox)fvMemberDetail.FindControl("txtHPhone");
TextBox txtWPhone = (TextBox)fvMemberDetail.FindControl("txtWPhone");
TextBox txtMPhone = (TextBox)fvMemberDetail.FindControl("txtMPhone");
DropDownList ddlPos = (DropDownList)fvMemberDetail.FindControl("ddlPos");
DropDownList ddlIsAdmin = (DropDownList)fvMemberDetail.FindControl("ddlIsAdmin");
bool blIsAdmin = false;
if (ddlIsAdmin.SelectedValue == "True") blIsAdmin = true;
TextBox txtComments = (TextBox)fvMemberDetail.FindControl("txtComments");
MemberBLL updateMemberInfo = new MemberBLL();
bool UpdateOK = updateMemberInfo.UpdateMemberByIdent(
txtFN.Text,
txtLN.Text,
ddlAddress.SelectedValue,
txtEmail.Text,
txtHPhone.Text,
txtWPhone.Text,
txtMPhone.Text,
blIsAdmin,
txtComments.Text,
Convert.ToInt32(ddlPos.SelectedValue),
Convert.ToInt32(id.Text));
}
else
{
//Display error - no user id cannot update record
}
}
linkbutton看起来像这样:
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
OnClick="MemberInfoUpdating" Text="Update" />
答案 0 :(得分:0)
这个LinkButton在哪里?如果它在FormView模板中,那么您可能需要使用类似的东西:
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
然后在DlMembers_ItemCommand中处理“更新”命令。
或者,将代码附加到FormView的OnItemUpdating事件而不是一些您不需要的额外事件:
<asp:FormView ID="fvMemberDetail" runat="server" OnItemUpdating="MemberInfoUpdating">