简体   繁体   English

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

[英]How to access ItemTemplate control from ItemCommand event using Repeater

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: 和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? 如何从ItemCommand中访问我的lblUpdateConfirm并将其Text状态变为可见,这样当用户看到新更新的ITemTemplate时,标签显示“Update Confirmed”消息?

VB: VB:

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

C #: C #:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ItemTemplate(中继器)内部的自定义控件,如何访问中继器项目中的值? - With a custom control that's inside of an ItemTemplate (Repeater), how can I access values from the repeater item? ItemCommand事件不会与Repeater控件一起触发 - ItemCommand event doesn't fire with the Repeater control 如何通过itemCommand在Repeater的itemtemplate中启用所有文本框控件? - How to enable all textbox controls in itemtemplate of Repeater by itemCommand? 中继器控件未使用ItemCommand更新 - Repeater control not updating with ItemCommand 中继器ItemCommand事件未触发 - Repeater ItemCommand event not firing 如何在子Repeater的ItemCommand事件中获取当前Repeater - How to get current Repeater in ItemCommand event of child Repeater ItemCommand事件不会与母版页中的中继器控件一起触发 - ItemCommand event doesn't fire with repeater control in master page 如何在ItemCommand事件上获取Repeater Item数据对象 - How to get Repeater Item data object on ItemCommand event 如何从中继器内的DataGrid中编码ItemCommand和OnDeleteCommand - How can i code ItemCommand and OnDeleteCommand From a DataGrid inside a Repeater 如何在c#.net中的嵌套转发器控件中触发ItemCommand参数子转发器 - How to fire ItemCommand argument child repeater in nested repeater control in c#.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM