Here I have written code that will help you out.
C#
protected string Values;
protected string dropdownValues;
protected void Save(object sender, EventArgs e)
{
string[] textboxValues = Request.Form.GetValues("DynamicTextBox");
JavaScriptSerializer serializer = new JavaScriptSerializer();
this.Values = serializer.Serialize(textboxValues);
int dropdownCount = hfDropDownIds.Value.Split(',').Length;
int count = 1;
string query = "INSERT INTO TABLENAME (DDL, TEXT1, TEXT2) VALUES";
int queryIntialLength = query.Length;
for (int i = 0; i < dropdownCount; i++)
{
Data data = new Data
{
DropDownListValue = Request.Form["ddl" + hfDropDownIds.Value.Split(',')[i]],
textBox1Value = textboxValues[count - 1],
textBox2Value = textboxValues[count]
};
dropdownValues = dropdownValues + data.DropDownListValue + ",";
query += string.Format("('{0}','{1}','{2}'),", data.DropDownListValue, data.textBox1Value, data.textBox2Value);
count = count + 2;
}
int queryFinalLength = query.Length;
if (queryFinalLength > queryIntialLength)
{
query = query.Remove(query.Length - 1, 1);
SaveData(query);
}
dropdownValues = dropdownValues.Remove(dropdownValues.Length - 1, 1);
dropdownValues = serializer.Serialize(dropdownValues.Split(',').ToArray());
}
private void SaveData(string query)
{
string connectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Data Class
public class Data
{
public string DropDownListValue { get; set; }
public string textBox1Value { get; set; }
public string textBox2Value { get; set; }
}
Screenshot