1

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?

Doug
  • 125
  • 2
  • 11
  • 22

1 Answers1

3

VB:

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

C #:

Label lblToMakeVisible = (Label)e.Item.FindControl("lblUpdateConfirm");
lblToMakeVisible.Visible = True;
NoAlias
  • 9,218
  • 2
  • 27
  • 46
  • Hmmm. Not working. VS2010 says "Cannot resolve symbol 'CType'.I've put your line of code just after the update in the ItemCommand event. Any other ideas are appreciated. – Doug Nov 26 '10 at 20:28
  • Thanks for the C# version, still not working: "Cannot cast expression ot type 'bool' to type 'Label' ". – Doug Nov 26 '10 at 20:43
  • What line of code do you get that error? The first line finds the label in that particular repeater item and then casts it as a label. The next line takes that casted label and sets the visibility to false. You do the same thing in your code example with DivEditContact. – NoAlias Nov 26 '10 at 20:51
  • Ok, my bad - had a typeo. So there is no error thrown now. The record gets updated, but the label's visibily stays hidden when returning to the ItemTemplate. Thank you... – Doug Nov 26 '10 at 21:15