if (IsPostBack && DDLCount > 0)
{
CreateDropDownLists();
}
}
public int DDLCount
{
get
{
object temp = ViewState["DDLCount"];
return temp == null ? 0 : (int)temp;
}
set
{
ViewState["DDLCount"] = value;
}
}
private void CreateDropDownLists()
{
if (DDLCount == 0)
DDLCount = Convert.ToInt32(TextBox4.Text);
for (int i = 0; i < DDLCount; i++)
{
DropDownList ddl = new DropDownList();
ddl.ID = "Text" + i;
LiteralControl l1 = new LiteralControl("<br></br>");
SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con1.Open();
string st = "select * from vassign"; //here we have use where cause minum number user dynamic control
SqlCommand cmd = new SqlCommand(st, con1);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ddl.Items.Add(dr.GetString(0).ToString());
}
con1.Close();
Panel4.Controls.Add(ddl);
Panel4.Controls.Add(l1);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con1.Open();
SqlCommand cmd1= new SqlCommand("insert into assign values('" + DropDownList1.SelectedValue.ToString() + "','" + DropDownList2.SelectedValue.ToString() + "','" + TextBox7.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "')", con1);
cmd1.ExecuteNonQuery();
con1.Close();
SqlConnection con2 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con2.Open();
string str2 = "select assign_id from assign where l_no='" + DropDownList2.SelectedValue + "'";
SqlCommand cmd2= new SqlCommand(str2, con2);
SqlDataReader dr2 = cmd2.ExecuteReader();
dr2.Read();
int assigned_id = dr2.GetInt32(0);
con2.Close();
string value2 = "";
for (int i = 0; i < DDLCount; i++)
{
DropDownList ddl = Panel4.FindControl("Text" + i) as DropDownList;
value2 = ddl.SelectedValue.ToString();
SqlConnection con = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("insert into assign_deo values('" + assigned_id + "','" + value2 + "','" + DropDownList1.SelectedValue.ToString() + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
DropDownList1.ClearSelection();
DropDownList2.ClearSelection();
TextBox7.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
for (int i = 0; i < DDLCount; i++)
{
DropDownList ddl = Panel4.FindControl("Text" + i) as DropDownList;
ddl.Dispose();
}
}