Click here to Skip to main content
15,997,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i have creating specific no of dynamic textboxes in gridview. i need to get those textboxes id's and textbox values. here i'm entering textbox values at the runtime, i want to compute those text box values please help me with this...
C#
protected void creategridview()
        {
            int number = a;
            DataTable dt = new DataTable();
            dt.Columns.Add("SerialNumber", typeof(string));
            dt.Columns.Add("MIN", typeof(string));
            dt.Columns.Add("MAX", typeof(string));
           // dt.Columns.Add("UNIT", typeof(string));
            dt.Columns.Add("Value", typeof(double));
            dt.Columns.Add("Result", typeof(string));
            for (int i = 0; i < number; i++)
            {
                dt.Rows.Add("", "", null);
            }
            gridview1.DataSource = dt;
            gridview1.DataBind();
        }
        protected void generaterow()
        {
            this.creategridview();
            int numbers = a;
            string serialno = b;
            string newserialno = serialno.Substring(0, serialno.Length - 1);
            int cellcnt = this.gridview1.Rows[0].Cells.Count;
            int rowcount = this.gridview1.Rows.Count;
                foreach (GridViewRow row in this.gridview1.Rows)
                {
                    Label label1 = new Label();
                    label1.ID = newserialno + (Convert.ToInt32(row.RowIndex + 1)).ToString();
                    label1.Text = newserialno + (Convert.ToInt32(row.RowIndex + 1)).ToString();
                    label1.Attributes.Add("runat", "server");
                    label1.CssClass = "color";
                    row.Cells[0].Controls.Add(label1);
                    //label2
                    Label label2 = new Label();
                    label2.ID = newserialno + (Convert.ToInt32(row.RowIndex + 1)).ToString();
                    label2.Text = min.ToString();
                    label2.Attributes.Add("runat", "server");
                    label2.CssClass = "color";
                    
                    row.Cells[1].Controls.Add(label2);
                    //label3
                    Label label3 = new Label();
                    label3.ID = newserialno + (Convert.ToInt32(row.RowIndex + 1)).ToString();
                    label3.Text = max.ToString();
                    label3.Attributes.Add("runat", "server");
                    label3.CssClass = "color";
                   
                    row.Cells[2].Controls.Add(label3);
                    //textbox1
                    TextBox textbox1 = new TextBox();
                    textbox1.ID = newserialno + (Convert.ToInt32(row.RowIndex + 1)).ToString();
                    textbox1.Attributes.Add("runat", "server");
                   
                   // textbox1.AutoPostBack = true;
                    row.Cells[3].Controls.Add(textbox1);
                    //label4
                    Label label4 = new Label();
                    label4.ID = newserialno + (Convert.ToInt32(row.RowIndex + 1)).ToString();
                   
                    label4.Attributes.Add("runat", "server");
                    label4.CssClass = "color";
                   
                    row.Cells[4].Controls.Add(label4);
                }
        }


here i created 3 labels and 1 textbox for each row in gridview. i need to add those textbox values...
so how do i get values in textboxes please tell me...

thank you...
Posted
Updated 6-Mar-15 20:55pm
v4
Comments
Where you want to get the values? Why there are so many loops? Can't you create the controls inside one loop?
Member 11207670 7-Mar-15 1:01am    
thanks for ur replay...
i need to create specific no of rows, if i give 30 in textbox it will generate 30 rows.
i want to add all textbox values and i want to store those values in the sql database..
So, what I understand is that you have a TextBox where you mention how many rows you want to add. Then you create those many rows. Right?

Now, question comes for generate row method. Where you are adding controls inside a loop which iterates for all the grid rows. So, why you have so many loops there? You can have only one loop and inside that you can add all the controls. Correct?
Member 11207670 7-Mar-15 1:21am    
if it works in one loop thats totally fine...
Yeah please move all your code to one loop. Why so many loops, it would slow down the application.

1 solution

 
Share this answer
 

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