1

我的中继器:

<asp:Repeater ID="rptrContacts" runat="server" OnItemCommand="rptrContact_ItemCommand" >

<div ID="itemTemplate>
<ItemTemplate>
<%# Eval("Name") %>
<%# Eval("Email") %>
<asp:LinkButton ID="lbtnEditContact" runat="server" CommandName="Edit"  Text="Edit"   CommandArgument='<%# Eval("ContactID") %>' />
<asp:Label ID="lblUpdateConfirm" runat="server" Text="Update Confirmed" Visible="false" />
</ItemTemplate>
</div>

<div ID="editTemplate runat="server" visibility="false">
Update your Info:<br>
Name: <asp:TextBox ID="txtName" runat="server Text="<%# Eval("Name") %>"/> <br>
Email:  <asp:TextBox ID="txtEmail" runat="server Text="<%# Eval("Email") %>"/><br>
<asp:LinkButton ID="lbtnUpdateContact" CommandArgument='<%# Eval("ContactID") %>'   CommandName="UpdateContact" runat="server" >Update</asp:LinkButton>
</div> 

</asp:Repeater

和 ItemCommand 的代码:

switch(e.CommandName)
{
case "Edit":
//make editTemplate div visible
HtmlGenericControl divEditContact = (HtmlGenericControl)e.Item.FindControl ("divEditContact");
divEditContact.Visible = true;
break;

case "Update":
Employee updateEmployee = new Employee
       {
           employeeName = txtName.Text:
           employeeEmail = txtEmail.Text:
       }

updateEmployee = API.UpdateEmployee(updateEmployee);

          //display lblUpdateConfirm visible to True
         // so user sees this confirm messge in the newly updated ItemTemplate

}

如何访问我的 lblUpdateConfirm 并将其文本状态从 ItemCommand 内部变为可见,以便当用户看到新更新的 ITemTemplate 时,标签显示“更新确认”消息?

4

1 回答 1

3

VB:

CType(e.Item.FindControl("lblUpdateConfirm"), Label).Visible = True;

C #:

Label lblToMakeVisible = (Label)e.Item.FindControl("lblUpdateConfirm");
lblToMakeVisible.Visible = True;
于 2010-11-26T20:19:34.203 回答