Click here to Skip to main content
15,920,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
this is my code. In this dynamic textboes generating three times. how they will generate one time
C#
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
   foreach (GridViewRow i in GridView1.Rows) 
   {
      CheckBox chkUpdate = (CheckBox)i.Cells[0].FindControl("CheckBox1");
      if (chkUpdate != null)
      {
         if (chkUpdate.Checked == true)
         {
            Label lab = (Label)i.FindControl("Label1");
            TextBox txt = (TextBox)i.FindControl("TextBox2");
            PlaceHolder ph = (PlaceHolder)i.FindControl("PlaceHolder1");
            if (txt.Text != "")
            {
               for (int j = 0; j < Convert.ToInt16(txt.Text); j++)
               {
                  Label la1 = new Label();
                  la1.Text = lab.Text + (j + 1).ToString();
                  //  la1.ID = "abc" + j;
                  using (SqlCommand comm = new SqlCommand("select [Serial_Number_Required] from Products where Product=@Product ", con))
                  {
                     con.Open();
                     //string Role = (string)(Session["Role"]);
                     // 2. define parameters used in command object
                     SqlParameter para = null;
                     para = new SqlParameter();
                     para.ParameterName = "@Product";
                     para.Value = lab.Text;
                     comm.Parameters.Add(para);

                     //Pass @Pages parameter

                     SqlDataReader reade = comm.ExecuteReader();
                     while (reade.Read())
                     {
                        Session["Serial_Number_Required"] = Convert.ToString(reade["Serial_Number_Required"]);
                     }

                     con.Close();
                     //Button Add = (Button)PreviousPage.FindControl("Button2");
                     if (Session["Serial_Number_Required"].ToString() == "Y")
                     {
                        ph.Controls.Add(la1);
                        ph.Controls.Add(new LiteralControl("<input id='txt' name='Textbox" + j + "'type='Text'  />"));

                        ph.Controls.Add(new LiteralControl("<br/>"));
                     }
                  }
               }
            }
         }
      }
   }
}


Code block added, indentation reduced
Posted
Updated 25-Aug-14 22:22pm
v2
Comments
[no name] 26-Aug-14 9:28am    
your question is clear to us

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