You must Sign In to post a response.
  • Category: .NET

    How to show table dynamically related to value entered in textbox

    hi all
    below is the code in aspx page which has a tablewith id=rav
    so what i want is i have a texbox and button control if i enter some value in textbox( ie users choice) and click on button the value how much ihave entered that much tables should be displayed

    so any body give me any examples or give me any idea





    <form id="form1" runat="server">
    <table class="auto-style1" id="rav" runat="server">
    <tr>
    <td class="auto-style2">  Children first name </td>
    <td class="auto-style31">   
    <asp:TextBox ID="TextBox7" runat="server" CssClass="auto-style37" Width="185px"></asp:TextBox>
     </td>
    </tr>
    <tr>
    <td class="auto-style2">  <span class="auto-style18">Children last name  </span></td>
    <td class="auto-style33">    <asp:TextBox ID="TextBox8" runat="server" CssClass="auto-style37" Width="186px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td class="auto-style2">  <span class="auto-style18"> Going to school?: </span></td>
    <td class="auto-style35">     
     <span class="auto-style18"> </span>
    <asp:RadioButton ID="RadioButton1" runat="server" CssClass="auto-style18" Text="Yes" />
    <asp:RadioButton ID="RadioButton2" runat="server" CssClass="auto-style18" Text="No" />
    </td>
    </tr>
    <tr>
    <td class="auto-style2">  <span class="auto-style18">school name : </span></td>
    <td class="auto-style31">   
    <asp:TextBox ID="TextBox9" runat="server" CssClass="auto-style38" Width="147px"></asp:TextBox>
     </td>
    </tr>
    <tr>
    <td class="auto-style2">  <span class="auto-style18">Grade :</span></td>
    <td class="auto-style33">      <asp:DropDownList ID="DropDownList1" cssClass="select" AutoPostBack="True" runat="server">
    <asp:ListItem>1st Grade</asp:ListItem>
    <asp:ListItem>2nd Grade</asp:ListItem>
    <asp:ListItem>3rd Grade</asp:ListItem>
    <asp:ListItem>4th Grade</asp:ListItem>
    <asp:ListItem>5th Grade</asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>
    <td><asp:Button ID="Button1" runat="server" Text="save" />
    </table>
    <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    </form>
    thanks®ards
    raviram
  • #762784

    Hello Velidi Viram,

    Refer the below code :

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Sample</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    Rows : <asp:TextBox ID="TextBoxRow" runat="server"></asp:TextBox>
     Columns : <asp:TextBox ID="TextBoxColumn" runat="server"></asp:TextBox>
     <asp:Button ID="ButtonCreateTable" runat="server" Text="Create Table"
    onclick="ButtonCreateTable_Click" />
    <br />
    <br />
    <asp:Panel ID="Panel1" runat="server">
    <asp:Table ID="Table1" runat="server">
    </asp:Table>
    </asp:Panel>
    </div>
    </form>
    </body>
    </html>


    Code - behind :

    protected void ButtonCreateTable_Click(object sender, EventArgs e)
    {
    // Total number of rows.
    int rowCnt;
    // Current row count.
    int rowCtr;
    // Total number of cells per row (columns).
    int cellCtr;
    // Current cell counter.
    int cellCnt;


    rowCnt = int.Parse(TextBoxRow.Text);
    cellCnt = int.Parse(TextBoxColumn.Text);

    for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
    {
    // Create a new row and add it to the table.
    TableRow tRow = new TableRow();
    Table1.Rows.Add(tRow);
    for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
    {
    // Create a new cell and add it to the row.
    TableCell tCell = new TableCell();
    tRow.Cells.Add(tCell);
    // Mock up a product ID.
    string prodID = rowCtr + "_" + cellCtr;

    // Add a literal text as control.
    tCell.Controls.Add(new LiteralControl(""));
    // Create a Hyperlink Web server control and add it to the cell.

    HyperLink h = new HyperLink();
    h.Target = "_blank";
    string linktovisit = "http://www.happiness4nirav.blogspot.in/";
    h.NavigateUrl = linktovisit;
    h.ToolTip = "Click here to visit : " + linktovisit;
    h.Text = "|" + rowCtr + ":" + cellCtr + "|";
    tCell.Controls.Add(h);
    }
    }
    }


    See the attached image. It's an output i have got using above code.


    Hope it will help you.


    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment


Sign In to post your comments