Click here to Skip to main content
15,886,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to create web application with multiple textbox insert to db (dynamic)

- First: I've bind question from my db and display it in Listview;
- Question: I would like to have textbox together with my question in the listview for Answer.

(If query and found 4 question then program should create 4 textbox for answer to each question)

Then in web application (Front) - clint input answer and click sumbit to update to data in the different table.

I really have issue with the multiple textbox return value then Insert to db table. Any Idea what I should read or Any function should I use.

What I have tried:

Behind:
private void BindQuestion()
{
    SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=master;");
    SqlDataAdapter sqlda = new SqlDataAdapter("Select * from dbo.Question", sqlcon);

    DataTable dtbl = new DataTable();
    sqlda.Fill(dtbl);

    dlExam.DataSource = dtbl;
    dlExam.DataBind();

}

Front:
<asp:DataList ID="dlExam" runat="server" DataMember="QID" BackColor="#F0F0F0">
            <ItemTemplate>
                <table width="800">
                    <tr>
                        <td align="left">
                            (<%#Container.ItemIndex+1 %>)  <asp:Label ID="QID" runat="server" Text='<%# Eval("Question") %>'></asp:Label>
                            <asp:Label ID="lblQuestionId" runat="server" Text='<%# Eval("QID") %>' Visible="false"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td align="left">
                           <asp:TextBox ID="rblAnswers" runat="server"></asp:TextBox>  
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                    </tr>
                </table>
            </ItemTemplate>
             <EditItemTemplate>
                  <asp:TextBox ID="Textbox" Style="width: 100px; background-color: white;" 
                                runat="server" CausesValidation="true" />

            </EditItemTemplate>
        </asp:DataList>

</asp:Content>

CommandArgument='<%# Eval("ID") %>
is not work for multiple textbox or dynamic textbox.

Thank you.!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900