Click here to Skip to main content
15,904,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to create a break between rows in a tablerow, like a line break.
This is the code am using but it is creating an inline block if I can say that.
html code:
ASP.NET
<form id="form1" runat="server">
   <div>
      <asp:Panel ID="PanelInstallInfo" runat="server">
                     <fieldset class="fieldset panelInfo">
                         <legend id="Legend1" class="legend" runat="server">Installement Info</legend>
                         <div runat="server" class="ContentForm" id="NumOfInst">
                             <asp:Label ID="NumInstal" runat="server" class="label">Number Of Installement :</asp:Label>
                             <asp:TextBox ID="txtNumberOfInstallment" runat="server" class="input"></asp:TextBox>
                             <asp:Button ID="BtnAction" runat="server" Text="Action" class="Buttom" OnClick="BtnAction_Click" />
                             <asp:Panel id="displayData" runat="server">
                             </asp:Panel>
                             <asp:Button ID="btnsave" runat="server" class="Buttom" OnClick="btnsave_Click" Text="Save" />
                             <asp:Button ID="btncancel" runat="server" class="Buttom" Text="Cancel" />
                             <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
                             <asp:Label ID="lbl_Error" runat="server" Text=""></asp:Label>
                       </div>
                       </fieldset>
              </asp:Panel>
   </div>
   </form>

c# code:

protected void BtnAction_Click(object sender, EventArgs e)
    {
        int number = Convert.ToInt32(txtNumberOfInstallment.Text);
        string top = "";
        int left = 0;
        TextBox txt;
        Label lb;
        Literal l;
        Table tb1 = new Table();
        tb1.ID = "tb1";
        Table tb2 = new Table();
        tb2.ID = "tb1";
        TableRow tr = new TableRow();
        for (int i = 1; i <= number; i++)
        {
            lb = new Label();
            lb.ID = "lbFname" + i.ToString();
            lb.Text = "Date" + i + ":";

            l = new Literal();
            l.Text = "<br/>";

            txt = new TextBox();
            txt.ID = "textBox" + i.ToString();//this will add the current number to textBox means textBox1, textBox2, textBox3 etc...
            txt.Attributes.Add("runat", "server");

            TableCell tc1 = new TableCell();
            tc1.Controls.Add(lb);
            tr.Controls.Add(tc1);
            tb1.Controls.Add(tr);

            TableCell tc2 = new TableCell();
            tc1.Controls.Add(txt);
            tr.Controls.Add(tc2);
            tb2.Controls.Add(tr);
           
        }
        displayData.Controls.Add(tb1);
        displayData.Controls.Add(tb2);
   }


Please can someone help??
Posted
Updated 27-Sep-13 22:59pm
v2
Comments
Andreas Gieriet 28-Sep-13 5:01am    
Your question is not clear enough. Can you post the expected result html code.
BTW: What is "literal" used for? It's nowhere used in your code, or am I missing something?
Cheers
Andi
El Dev 28-Sep-13 5:15am    
Hi Andreas!
I tried to use literal inorder to hold the line break tag without using a table and it child control. this work fine but watever I am trying to use the table control it is not working...But what am wondering is forget the literal control and try to put a line break between rows.Because I want to enter an integer in my textBox and get generated textboxes in different rows not to a same row.

1 solution

Hello mate,

I tried your code and it turns out that you have created only one
C#
TableRow 
object and used in all the iterations. So no matter how many time you add the same TableRow object in a Table it will consider it as one row, so here is what you should do if you want one TextBox in one row.

C#
for (int i = 1; i <= number; i++)
        { tr = new TableRow();


create a new object of TableRow at the start of each iteration. it'll work.

Cheers, good luck
 
Share this answer
 
Comments
El Dev 28-Sep-13 5:58am    
Thanks Asif!

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