Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
hi to All Technical experties,
 
1-my requirementis ..How to save dynamic table created textbox values ,row index,column idex into database table using aps.net c#.here is my cose..i can create dynamic table.but no idea abt how to save.i have database table columns (textboxvalue.row number,column number).here is my code
 
1- 1.aspx page
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
   
    <%--<form id="form1" runat="server">--%>
    
    <div>
        Rows:<asp:TextBox ID="txtRows" runat="server" Width="39px"> <br />
        Cols:  <asp:TextBox ID="txtCols" runat="server" Width="37px">
        <br />
        <br />
        <asp:Button ID="btnGenerate" OnClick="btnGenerate_Click" runat="server" Text="Generate" /> <br /> <br />
        <asp:PlaceHolder ID="PlaceHolder1" runat="server">
        <br />
        <br />
        <br />
   
    <%--</div>
        <asp:Button ID="btnPost" runat="server" OnClick="Button1_Click" Text="Cause Postback" />--%>   <%-- </form>--%>
 
2-1.aspx.cs page
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                //Set the Rows and Columns property with the value
                //entered by the user in the respective textboxes
                this.Rows = Int32.Parse(txtRows.Text);
                this.Columns = Int32.Parse(txtCols.Text);
            }
 
            CreateDynamicTable();
 

        }
        protected int Rows
        {
            get
            {
                return ViewState["Rows"] != null ? (int)ViewState["Rows"] : 0;
            }
            set
            {
                ViewState["Rows"] = value;
            }
        }
        protected int Columns
        {
            get
            {
                return ViewState["Columns"] != null ? (int)ViewState["Columns"] : 0;
            }
            set
            {
                ViewState["Columns"] = value;
            }
        }
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            CreateDynamicTable();
        }
        private void CreateDynamicTable()
        {
            PlaceHolder1.Controls.Clear();
 
            // Fetch the number of Rows and Columns for the table 
            // using the properties
            int tblRows = Rows;
            int tblCols = Columns;
            // Create a Table and set its properties 
            Table tbl = new Table();
            // Add the table to the placeholder control
            PlaceHolder1.Controls.Add(tbl);
            // Now iterate through the table and add your controls 
            for (int i = 0; i < tblRows; i++)
            {
                TableRow tr = new TableRow();
                for (int j = 0; j < tblCols; j++)
                {
                    TableCell tc = new TableCell();
                    TextBox txtBox = new TextBox();
                    //txtBox.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j;
                    // Add the control to the TableCell
                    tc.Controls.Add(txtBox);
                    // Add the TableCell to the TableRow
                    tr.Cells.Add(tc);
                }
                // Add the TableRow to the Table
                tbl.Rows.Add(tr);
            }
 
            // This parameter helps determine in the LoadViewState event,
            // whether to recreate the dynamic controls or not

            ViewState["dynamictable"] = true;
        }
    }
}
i can create table but dont know how to save.help me plz..
 
thanks
papu
Posted 22-Nov-12 2:48am
Edited 22-Nov-12 2:51am
v2
Comments
mujtabakhan 2 at 11-Apr-13 5:45am
   
hii!!
myself m s khan, i have a problem in creating a table in a database from asp.net..
any body tell me how to create new table using textbox..
regards
m s khan

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

  Print Answers RSS
0 OriginalGriff 280
1 Sergey Alexandrovich Kryukov 279
2 CPallini 205
3 Maciej Los 197
4 Afzaal Ahmad Zeeshan 160
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100