rsbadhan
asked on
reading textbox values from repeater
hi,
I want to read back values in a textbox form a repeater. Initally the textboxes gat their values from a database...
I want to read all the values and then when one update button (outside the repeater) is pressed so it can recalcuate and add records back to the database. (I think i can acheive this part via sql) as long as i had the new qty in the textbox and an id number for the row to update... any ideas... my repeater looks like this...i guess the id can be retreived by tying each textbox to a unique ID <id=databinder.eval()..
<ItemTemplate>
<table width="700"> <tr>
<td width="175" class="lblBlue"><%# trimName(databinder.eval(C ontainer.d ataitem, "ProductName"))%></td>
<td width="75" class="lblBlue"><%# databinder.eval(Container. dataitem, "strength") %></td>
<td width="75" class="lblBlue"><%# databinder.eval(Container. dataitem, "pacSize") %></td>
<td width="75" class="lblBlue"><%# databinder.eval(Container. dataitem, "StorageForm") %></td>
<td width="50" class="lblBlue" align="center">
<asp:TextBox Runat=server Width=15 Text='<%# databinder.eval(Container. dataitem, "qty") %>' MaxLength=1>
</asp:TextBox></td>
<td width="75" class="lblBlue"><%#(databi nder.eval( Container. dataitem, "Newprice"))%>
<td width="50" class="lblBlue"><%# databinder.eval(Container. dataitem, "subtotal") %><br>
</td>
<td width="50" class="sideMenu1Txt">
<asp:linkbutton Runat="server" CommandName="delitem" CommandArgument='<%# databinder.eval(Container. dataitem, "Productid") '>remove</asp:linkbutton>< /td>
</tr>
</table>
</ItemTemplate>
I want to read back values in a textbox form a repeater. Initally the textboxes gat their values from a database...
I want to read all the values and then when one update button (outside the repeater) is pressed so it can recalcuate and add records back to the database. (I think i can acheive this part via sql) as long as i had the new qty in the textbox and an id number for the row to update... any ideas... my repeater looks like this...i guess the id can be retreived by tying each textbox to a unique ID <id=databinder.eval()..
<ItemTemplate>
<table width="700"> <tr>
<td width="175" class="lblBlue"><%# trimName(databinder.eval(C
<td width="75" class="lblBlue"><%# databinder.eval(Container.
<td width="75" class="lblBlue"><%# databinder.eval(Container.
<td width="75" class="lblBlue"><%# databinder.eval(Container.
<td width="50" class="lblBlue" align="center">
<asp:TextBox Runat=server Width=15 Text='<%# databinder.eval(Container.
</asp:TextBox></td>
<td width="75" class="lblBlue"><%#(databi
<td width="50" class="lblBlue"><%# databinder.eval(Container.
</td>
<td width="50" class="sideMenu1Txt">
<asp:linkbutton Runat="server" CommandName="delitem" CommandArgument='<%# databinder.eval(Container.
</tr>
</table>
</ItemTemplate>
You can use following code for looping in Repeater in adding value 1 by 1:
Dim sum As Double
For Each ri As RepeaterItem In Repeater1.Items
Dim _tb as TextBox = CType(ri.FindControl("Text Box1"), Repeater)
sum = sum + CType( _tb.Text, Double )
Next
-tushar
Dim sum As Double
For Each ri As RepeaterItem In Repeater1.Items
Dim _tb as TextBox = CType(ri.FindControl("Text
sum = sum + CType( _tb.Text, Double )
Next
-tushar
Hi rsbadhan,
for ( int index=0; index < repeaterId.Items.Count; index++ )
{
TextBox tb = (TextBox)repeaterId.Items[ index].Fin dControl(" TextBoxID" );
}
but you have to declare ID property of the TextBox control
<asp:TextBox Runat=server Width=15 Text='<%# databinder.eval(Container. dataitem, "qty") %>' MaxLength=1 ID="yourID">
</asp:TextBox>
B..M
for ( int index=0; index < repeaterId.Items.Count; index++ )
{
TextBox tb = (TextBox)repeaterId.Items[
}
but you have to declare ID property of the TextBox control
<asp:TextBox Runat=server Width=15 Text='<%# databinder.eval(Container.
</asp:TextBox>
B..M
ASKER
UCtlsearch1_srchTxt .... this will be my productID? i.e id of the textbox
ASKER
tushar
getting a symtax error ...ri is not declared...
RS
getting a symtax error ...ri is not declared...
RS
Correction:
Dim sum As Double
For Each ri As RepeaterItem In Repeater1.Items
Dim _tb as TextBox = CType(ri.FindControl("Text Box1"), TextBox) ' Corrected this line
sum = sum + CType( _tb.Text, Double )
Next
double sum;
foreach (RepeaterItem ri in Repeater1.Items) {
TextBox _tb = ((Repeater)ri.FindControl( "TextBox1" ));
sum = sum + ((double)_tb.Text);
}
Dim sum As Double
For Each ri As RepeaterItem In Repeater1.Items
Dim _tb as TextBox = CType(ri.FindControl("Text
sum = sum + CType( _tb.Text, Double )
Next
double sum;
foreach (RepeaterItem ri in Repeater1.Items) {
TextBox _tb = ((Repeater)ri.FindControl(
sum = sum + ((double)_tb.Text);
}
Again in C#
double sum;
foreach (RepeaterItem ri in Repeater1.Items) {
TextBox _tb = ((TextBox)ri.FindControl(" TextBox1") );
sum = sum + ((double)_tb.Text);
}
-tushar
double sum;
foreach (RepeaterItem ri in Repeater1.Items) {
TextBox _tb = ((TextBox)ri.FindControl("
sum = sum + ((double)_tb.Text);
}
-tushar
ASKER
VB code behind is fine... where do i declare ri ?
think i just need to declare it and it will be exaclty waht i need...
RS
think i just need to declare it and it will be exaclty waht i need...
RS
When you use For Each ri As ReapeterItem then ri is declared in the For loop itself...
but since you are getting such error.. you can try declareing it before for each loop...
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Dim sum As Double
Dim ri As RepeaterItem
For Each ri In Repeater1.Items
Dim _tb as TextBox = CType( ri.FindControl("TextBox1") , TextBox) ' Corrected this line
sum = sum + CType( _tb.Text, Double )
Next
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
-tushar
but since you are getting such error.. you can try declareing it before for each loop...
--------------------------
Dim sum As Double
Dim ri As RepeaterItem
For Each ri In Repeater1.Items
Dim _tb as TextBox = CType( ri.FindControl("TextBox1")
sum = sum + CType( _tb.Text, Double )
Next
--------------------------
-tushar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok problem i am having is...
1. i have declared the <asp:textbox id=textbox1 .... ( *********is that correct?)
2. Does it need autopostback=true for the value change to be recognised? (customers can change theis value, which is why it has to recalculate)
3. i need basically an array of all the values in the repeater.. old and new..(ALL the ones in the textboxes in the repeater)
it reads old values but not the changed ones
Thanks for you sticking with this.
RS
1. i have declared the <asp:textbox id=textbox1 .... ( *********is that correct?)
2. Does it need autopostback=true for the value change to be recognised? (customers can change theis value, which is why it has to recalculate)
3. i need basically an array of all the values in the repeater.. old and new..(ALL the ones in the textboxes in the repeater)
it reads old values but not the changed ones
Thanks for you sticking with this.
RS
ASKER
thi sis what i have so far
<asp:TextBox ID=textbox1 Runat=server Width=15 Text='<%# databinder.eval(Container. dataitem, "qty") %>' MaxLength=1>
</asp:TextBox></td>
Sub readTxtBox()
Dim x As Integer
Dim ri As RepeaterItem
x = Repeater1.Items.Count
Dim qtys(x) As String
For Each ri In Repeater1.Items
Dim _tb As TextBox = CType(ri.FindControl("Text Box1"), TextBox)
qtys(x) = _tb.Text
x = +1
Next
End Sub
but it only reads the value that is first in the textbox..ie the one from the database...not the one the user is entering
<asp:TextBox ID=textbox1 Runat=server Width=15 Text='<%# databinder.eval(Container.
</asp:TextBox></td>
Sub readTxtBox()
Dim x As Integer
Dim ri As RepeaterItem
x = Repeater1.Items.Count
Dim qtys(x) As String
For Each ri In Repeater1.Items
Dim _tb As TextBox = CType(ri.FindControl("Text
qtys(x) = _tb.Text
x = +1
Next
End Sub
but it only reads the value that is first in the textbox..ie the one from the database...not the one the user is entering
ASKER
ok, thanks for your help.. the issue is postback, i have to load the repeater only once if not postback then it works fine
srchTxt = _myUC_SrchTxt.Text