Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a control within a repeater 2

Status
Not open for further replies.

rrhandle

Programmer
Dec 26, 2001
193
US

I have a repeater:

Code:
<asp:Repeater id="PendPmtRepeater" runat="server">
 <ItemTemplate>
   <tr>
    <td class="small">
      <%# DataBinder.Eval(Container.DataItem, "ApptDate")%></td>
    <td class="small" align="right">
      <%# DataBinder.Eval(Container.DataItem, "Timeslot")%></td>
    <td class="small" align="center">
       <%# DataBinder.Eval(Container.DataItem, "shorthand")%></td>
    <td class="small" align="center">$
       <%# DataBinder.Eval(Container.DataItem, "amount")%></td>
       <td class="small" align="center">
         <asp:Button id="Button1" runat="server" 
         OnClick="MyRepeaterButton_Click" Text="Pay" /></td>
  </tr>
 </ItemTemplate>
</asp:Repeater>

I need to hide or show the button depending on the value "amount".

Any ideas?

Thanks

 
rrhandle: There are a couple of ways to do this; one way is to use a helper function (I saw a few on a quick Google search) but you can also approach this from the ItemDataBound event of the Repeater.
Code:
Sub PendPmtRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
  If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then 
    Dim MyButton As WebControls.Button
    If e.Item.DataItem("amount") > 50 Then
     MyButton = CType(e.Item.FindControl("Button1"), WebControls.Button)
     MyButton.Visible="false"      
    End If 
 End If
End Sub 
..and place the ItemDataBound event in the repeater object as:
<asp:Repeater id="PendPmtRepeater" runat="server" OnItemDataBound="PendPmtRepeater_ItemDataBound">
There are probably 2 or 3 ways to accomplish this. Remember to check for NULLS in the amount field as an exception will be thrown , etc.
 
Isadore, EXCELLENT!

This is why only Tek-Tips gets me monthly $$$. And worth every penny.

Thanks again.

 
rrhandle - glad I could help - always keep in mind when it comes to dot NET there's 6 ways to skin every issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top