如何使用 Repeater 从 ItemCommand 事件访问 ItemTemplate 控件

发布于 2024-10-04 19:18:37 字数 1711 浏览 1 评论 0原文

我的中继器:

<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 时,标签显示“更新已确认”消息?

My repeater:

<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

and code for 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

}

How can I access my lblUpdateConfirm and turn its Text state to visible from inside the ItemCommand, so that when the user sees the newly updated ITemTemplate, the label is showing the "Update Confirmed" message?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鼻尖触碰 2024-10-11 19:18:37

VB:

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

C#:

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

VB:

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

C #:

Label lblToMakeVisible = (Label)e.Item.FindControl("lblUpdateConfirm");
lblToMakeVisible.Visible = True;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文