Link to home
Start Free TrialLog in
Avatar of JRockFL
JRockFLFlag for United States of America

asked on

Insert textboxes values from repeater into database

I have a repeater, that repeats over a textbox. I am trying to insert the values of all 4 textboxes into the database.

 <asp:Repeater ID="rpComp" runat="server">
                        <HeaderTemplate>
                        <table>                      
                       
                        </HeaderTemplate>
                            <ItemTemplate>
                            <tr>
                            <td>
                                <%#Eval("Course")%>
                            </td>
                            <td>
                                <asp:TextBox ID="txtQuestion3" runat="server" Width="25"></asp:TextBox>
                            </td>
                            </tr>
                            </ItemTemplate>
                            <FooterTemplate>                          
                            </table>
                            </FooterTemplate>
                        </asp:Repeater>  

I have to be able to insert the data something like this...
srBll.SaveResultsToDatabase(tb1, tb2, tb3, tb4)
Avatar of jeebukarthikeyan
jeebukarthikeyan
Flag of India image

hi,

TextBox txt;
                  for( int i=0;i<Repeater1.Items.Count;i++)
                  {
                        txt=(TextBox)Repeater1.Items[0].FindControl("txtQuestion3");
                        Response.Write( txt.Text);
                  }

b u d d h a
ASKER CERTIFIED SOLUTION
Avatar of jeebukarthikeyan
jeebukarthikeyan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JRockFL

ASKER

Thanks for your reply, but I need to be able to insert all of the values into the database, by passing 4 values to my saveresults sub.

For example..
srBll.SaveResultsToDatabase(tb1, tb2, tb3, tb4)

Is it possible to create 4 variables and set the values?
hi,

just think if ur repeater is like this

  <asp:repeater id="Repeater1" runat="server">
  <ItemTemplate>
    <asp:TextBox ID="txtQuestion1" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>'>      
    </asp:TextBox>
    <asp:TextBox ID="txtQuestion2" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>'>      
    </asp:TextBox>
   <asp:TextBox ID="txtQuestion3" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>'>      
    </asp:TextBox>
  </ItemTemplate>
  </asp:repeater>

  code behind

  TextBox txt1;
  TextBox txt2;
  TextBox txt3;
  for( int i=0;i<Repeater1.Items.Count;i++)
  {
    txt1 = (TextBox)Repeater1.Items[0].FindControl("txtQuestion1");
    txt2 = (TextBox)Repeater1.Items[0].FindControl("txtQuestion2");
    txt3 = (TextBox)Repeater1.Items[0].FindControl("txtQuestion3");

    srBll.SaveResultsToDatabase(txt1.Text , txt2.Text , txt3.Text)
  }

  b u d d h a
Avatar of JRockFL

ASKER

thank you very much! that is what i needed.
Avatar of JRockFL

ASKER

What about finding the control if the textbox is in the footer?

                            <FooterTemplate>
                            <tr>
                            <td>Other courses</td>
                            <td><asp:TextBox ID="txtOtherCourses" runat="server" Width="25" onFocus="startCalc();" onBlur="stopCalc();"></asp:TextBox>%</td>
                            </tr>
                            </table>
                            </FooterTemplate>