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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help reading text boxes in a repeater control 1

Status
Not open for further replies.

ProfReynolds

Programmer
Sep 12, 2001
96
US
I'm sure that I'm just brain dead. But any help would sure be appreciated.

I have a repeater control with 4 columns: Qty, Desc, Unit, Extension. The Desc and UnitPrice columns are populated from the database, the user entered in a text box for the first column, and I calculate the last column.

But I can't seem to get reference to these text boxes.

Any ideas?

<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table align="center" border="0" cellpadding="2" cellspacing="2" width="550">
<tr>
<th bgcolor="#cccccc" width="15%" align="center">Quantity</th>
<th bgcolor="#cccccc" width="55%" align="left">Product Name</th>
<th bgcolor="#cccccc" width="15%" align="right">Unit Price</th>
<th bgcolor="#cccccc" width="15%" align="right">Extension</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:TextBox ID="TextBox1" runat="server" Text="0"
AutoPostBack="true" ></asp:TextBox>
</td>
<td align="left"><%# Eval("ProductName")%></td>
<td align="right"><%# Eval("UnitPrice")%></td>
<td align="right"></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
 
Use the ItemDataBound Event of the repeater:
Code:
Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound[b]
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
   Dim tb As New TextBox
   tb = ctype(e.Item.FindControl("<your textbox >")
''You can access the text of the textbox:
''somevar = tb.text
   End If
End Sub[/b]

Jim
 
That was excellent help.

Part two of the same question. Now I need to go back and read those text boxes. When the boxes were created, I assigned an ID to them.

Code:
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) ||
            (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            TextBox TB=new TextBox();
            TB = (TextBox)e.Item.FindControl("TextBox1");
            TB.Text = e.Item.UniqueID.ToString();
            TB.ID="txt" + TB.Text.Substring(TB.Text.Length-2);
            TB.Text = TB.ID.ToString();
        }
    }

Is there a way that I can either reference those textboxes directly, or parse through the repeater's rows, find the boxes, and read the contents then?
 
Do you mean like clicking a button and looping through the repeater? Try something like this in a button click event. This is VB, but you can convert it to C# easily as I have seen from your last post:
Code:
Dim ri As RepeaterItem
Dim i as Integer
For x = 0 To Repeater1.Items.Count - 1
   If ri.ItemType = ListItemType.Item OR ri.ItemType = 
      ListItemType.AlternatingItem Then
      Dim tb As New TextBox
      tb = t.FindControl("TextBox1")
   End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top