How to Upload Dynamic Created textbox values into Database at a time

Posted by Satish.madugundu under ASP.NET on 8/26/2011 | Points: 10 | Views : 1421 | Status : [Member] | Replies : 1
Hi
I am creating n no of rows [ each row consisting of 6 text boxes] dynamically.
when I enter the values into these text boxes, only final row values are inserting into database table.
but the I am not creating rows at a time, first I will create one row after entering values into i vl create another row.
I am showing my UI in screen shot. how to upload all values into db, can you any one tell suggest me please.
here I am showing my code snippet for inserting values into db
CODE:
//upload data into db
protected void Button2_Click(object sender, EventArgs e)
{
string strText = string.Empty;
for (int i = 0; i < 6; i++)
{

string txtvalue = "txtBox" + i.ToString() + ctr;
TextBox txt = (TextBox)divdyn.FindControl(txtvalue);
if (txt != null)
{
strText = strText + "," + txt.Text;
}
}
string stringvalues = strText.Trim(',').ToString();
char[] separator = new char[] { ',' };
string[] strSplitArr = stringvalues.Split(separator);
string str1 = strSplitArr[0].ToString();
string str2 = strSplitArr[1].ToString();
string str3 = strSplitArr[2].ToString();
string str4 = strSplitArr[3].ToString();
string str5 = strSplitArr[4].ToString();
string str6 = strSplitArr[5].ToString();
con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
con.Open();
com = new SqlCommand("insert into uploadreports values('" + str1 + "','" + str2 + "','" + str3 + "','" + str4 + "','" + str5 + "','" + str6 + "')", con);
com.ExecuteNonQuery();
con.Close();

}

Thanks in Advance
Satish Madugundu




Responses

Posted by: Satish.madugundu on: 8/26/2011 [Member] Starter | Points: 25

Up
0
Down
kindly find the screen shot
 Download source file

Satish.madugundu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response