2010-11-26 32 views
0
訪問的ItemTemplate控制

我的中繼器:如何從ItemCommand事件使用直放站

<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時,標籤顯示「更新已確認」消息?

回答

2

VB:

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

C#:

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

嗯。不工作。 VS2010表示「無法解析符號'CType'。我在ItemCommand事件中更新了代碼行之後,其他任何想法都可以使用。 – Doug 2010-11-26 20:28:13