hi all, I have a problem on creating the multiple TextBoxs for inserting multiple row into oracle(10g) database. Line 41: <% for (int i=0; i<InsertRow;i++) {%> Line 42: <tr> Line 43: <td><asp:TextBox ID='<% PortNo %>' runat="server"></asp:TextBox></td> Line 44: <td><asp:TextBox ID='<% Model %>' runat="server"></asp:TextBox></td> Line 45: </tr> Parser Error Message: '<% PortNo %>' is not a valid identifier. I guess it is a sytax error. can anyone help me. PLZ! !
Thanks for your reply, I have tried your method. But still fail to create multiple "TestBoxID" using array. Line 41: <% for (int i=0; i<InsertRow;i++) {%> Line 42: <tr> Line 43: <td><asp:TextBox ID='<%=PortNo %>' runat="server"></asp:TextBox></td> Line 44: <td><asp:TextBox ID='<%= Model %>' runat="server"></asp:TextBox></td> Line 45: </tr> Parser Error Message: '<%=PortNo %>' is not a valid identifier.
Make sure that the PortNo and Mode variables are declared at the class level and that they are marked at least protected. If they are private and/or defined as local to a method they will not be available to page.
<asp:textbox id="<%=PortNo%>" runtat="server"> Hello World! </asp:textbox> try this hopefully problem will be solved
No, you cannot - and should not - attempt to generate the ID attribute with a code rendering block/expression. I assume that you have som kind of iteration going on here, since thereùs an index i. You really should use a repeater for this. Consult the documentation for the asp:Repeater control.
hello: I still fail to create mutiple "Testbox" ID using array. I have set the array to be global varible. So, How to use [asp:Repeater control] to achieve it? Thanks
you can run through a loop with the codebehind create a form, or fieldset in the form with an ID and runat="server" then do a loop defining: for x as integer = 0 to 10 dim newTxtBox as TextBox newTxtBox.ID = "Box_" & x fieldset.controls.add(newTxtBox) next Something like that...
Thanks for your reply: here is the full code, but i am stuck over this error for a long time. Help me PLZ. error'<%=PorNo %>' is not a valid identifier) <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Data" %> <HTML> <HEAD> <title>----Mutiplie insertion----</title> <script language="C#" runat="server"> int InsertRow; string[] Model; string[] PortNo; string insertCmd; public void RowCreated(Object Src, EventArgs E) { InsertRow = int.Parse(RowNumber.Text); for(int i=0;i<InsertRow;i++) { Model = new string[InsertRow]; PortNo = new string[InsertRow]; Model="Model"+i.ToString(); PortNo="PortNo"+i.ToString(); } } private void RowInsert(Object Src, EventArgs E) { OleDbConnection myConnection = new OleDbConnection("Provider=MSDAORA;Data Source=****;User ID=System;Password=****"); for(int k=0; k<InsertRow; k++) { insertCmd = "insert into db2 values('"+PortNo[k].Text+"','"+Model[k].Text+"')"; OleDbCommand myCommand = new OleDbCommand(insertCmd, myConnection); myConnection.Open(); myCommand.ExecuteNonQuery(); } } </script> </HEAD> <body> <form runat="server"> <table cellpadding="0" cellspacing="0" border="1"> <tr> <td colspan="2">Number of Rows: <asp:TextBox ID="RowNumber" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Submmit" OnClick="RowCreated" /></td> </tr> <tr> <td>Model</td> <td>PortNo</td> </tr> <% for (int i=0; i<InsertRow;i++) {%> <tr> <td><asp:TextBox ID='<%=PorNo %>' runat="server"></asp:TextBox></td> <td><asp:TextBox ID='<%=Model %>' runat="server"></asp:TextBox></td> </tr> <%} %> <tr> <td><asp:Button ID="Insert" runat="server" Text="Insert" OnClick="RowInsert" /></td> </tr> </table> <asp:Label ID="Message" runat="server"></asp:Label> </form> </body> </HTML>
Maybe I'm not reading it right, or not reading your question right, so if I'm way off please ignore. It looks like you want to dynamically add textbox controls to your HTML page based on the iteration through the count of the 'i' variable. I have to agree with an earlier post that a Repeater Server control might make this a lot easier. Then you can create the template client side and bind your data server side. If you look up examples for the 'Repeater' control I'm sure you'll find quite a bit. When I look at the code you have inline with your HTML, I see that you create a for-next loop while i<InsertRow. This looks fine, but if the actual html for the textbox that you are making is not inside the server side code (<% ... %>), then how does it become in the loop? As it is now, it will only show up once. You have to take that HTML that you want in the loop, surround it by your server side code brackets, and then do a Response.Write("<input.....>"); for all of the html that you want dynamically rendered. I think the reason you get the error is because the loop with the i is already done before it gets to the place where you want to use it. Does that make sense? Let me know if it does not and I can make an example... Hope that helps.
I get your points. It lets me know why i make such error. but i still feel difficulties to complete it. Could you make an example for me. Thanks so much.
Something along the lines of what I changed in red below: <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Data" %> <HTML> <HEAD> <title>----Mutiplie insertion----</title> <script language="C#" runat="server"> int InsertRow; string[] Model; string[] PortNo; string insertCmd; public void RowCreated(Object Src, EventArgs E) { InsertRow = int.Parse(RowNumber.Text); for(int i=0;i<InsertRow;i++) { Model = new string[InsertRow]; PortNo = new string[InsertRow]; Model="Model"+i.ToString(); PortNo="PortNo"+i.ToString(); } } private void RowInsert(Object Src, EventArgs E) { OleDbConnection myConnection = new OleDbConnection("Provider=MSDAORA;Data Source=****;User ID=System;Password=****"); for(int k=0; k<InsertRow; k++) { insertCmd = "insert into db2 values('"+PortNo[k].Text+"','"+Model[k].Text+"')"; OleDbCommand myCommand = new OleDbCommand(insertCmd, myConnection); myConnection.Open(); myCommand.ExecuteNonQuery(); } } </script> </HEAD> <body> <form runat="server"> <table cellpadding="0" cellspacing="0" border="1"> <tr> <td colspan="2">Number of Rows: <asp:TextBox ID="RowNumber" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Submmit" OnClick="RowCreated" /></td> </tr> <tr> <td>Model</td> <td>PortNo</td> </tr> <% for (int i=0; i<InsertRow;i++) { Response.Write("<tr>"); Response.Write("<td><input ID='" + PorNo + "'></td>"); Response.Write("<td><input ID='" + Model + "'></td>"); Response.Write("</tr>"); } %> <tr> <td><asp:Button ID="Insert" runat="server" Text="Insert" OnClick="RowInsert" /></td> </tr> </table> <asp:Label ID="Message" runat="server"></asp:Label> </form> </body> </HTML>
thanks for help I found there are lots of problems in my original program. (not only just assigning the "ID" of "Textboxs", but also the insertion of the such data through the function"private void RowInsert(Object Src, EventArgs E)") Could you post the codes which can insert mutiple rows into database(oracle) using asp.net and C#. I really need it and time is not on my side. thanks.