controls withing a repeater control

sdlangers

Centurion
Joined
Dec 3, 2002
Messages
118
hi,

i have a repeater control bound to some xml that i load in. it renders fine and i get a number of rows flushed out to my aspx page.

one of the fields in these rows is a textbox, which i want to be updateable - so i have a button at the end of each row called update.

by using the commandArgument parameter on that button, i can pass it the row id, so i know which row's update button was clicked.

but how do i get the text from the textbox ? how do i distinguish which textbox it is

here's the aspx code:

Visual Basic:
<asp:Repeater id="rptConfs" runat="server">				
				<ItemTemplate>
				<tr>
					<td><%#container.dataitem("confirmno")%></td>
					<td align="center"><INPUT id="txtParts" type="text" size="5" name="txtParts" runat="server" value=<%#container.dataitem("numberoflines")%>></td>
					<td align="center"><asp:Button id="btnUpdate" OnClick="btnUpdate_Click" text="Update" commandArgument=<%# container.dataitem("CONFIRMNO") %> runat="server"></asp:Button></td>
				</tr>
				</ItemTemplate>
				</asp:Repeater>

and here's what i have for the vbCode :

Visual Basic:
Public Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        ' update record
        Try
            Dim confNo As String = sender.CommandArgument
	    response.write ("new value = " & .................)
	    response.end

        Catch er As Exception
            showError("ERROR: UpdateConf - " & er.ToString)
        End Try
    End Sub

so i basically need to know how to get the value from the textbox

thanks!
 
Accessing Controls inside a Repeater control

Hi,

your can do this using the Repeater event OnItemCommand, because this is the one activates each time a buttons that exists within a repeater control is clicked, and in the code you can do something like this.

<asp:Repeater ID="repeater" Runat="server" OnItemCommand="repeater_ItemCommand">
<HeaderTemplate>
<table border="1">
<tr>
<td>Customer Name</td>
<td> </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><input type="text" id="customerName" runat="server" value="<%DataBinder.Eval(Container.DataItem, "CustomerName")%>" NAME="customerName"></td>
<td><asp:Button ID="update" Runat="server" CommandName="Update" Text="Update"/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>


<script runat="server" language="c#" >
void repeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Updade")
{
string selectedCustomerName = ((HtmlInputText)e.Item.FindControl("customerName")).Value;
}
}
</script>
 
Back
Top