dynamic textbox in repeater
-
string text1 = "";
string text2 = "";private void insertfiles()
{foreach (RepeaterItem item in Rptdescription.Items) { TextBox txt1 = (TextBox)item.FindControl("TextBox1"); TextBox txt2 = (TextBox)item.FindControl("TextBox3"); text1 += txt1.Text + "|"; text2 += txt2.Text + "|"; } foreach (string split2 in text2.Split('|')) { stringList.Add(split2 + "<br/>"); SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings\["ConnectionString"\]); SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCnn; SqlCnn.Open(); SqlCmd.CommandText = "insert into test(test,id) values(@test,1)"; SqlParameter DataBaseID = new SqlParameter("@test", SqlDbType.NVarChar, 50); DataBaseID.Value = stringList.Add(split2); SqlCmd.Parameters.Add(DataBaseID); SqlCmd.ExecuteNonQuery(); SqlCnn.Close(); Bindrepeater(); }
//ignore syntax errors
This is how im inserting values in textbox into db.. but im having two textboxes how i need to insert both values at a time.. into db... thank you..
-
string text1 = "";
string text2 = "";private void insertfiles()
{foreach (RepeaterItem item in Rptdescription.Items) { TextBox txt1 = (TextBox)item.FindControl("TextBox1"); TextBox txt2 = (TextBox)item.FindControl("TextBox3"); text1 += txt1.Text + "|"; text2 += txt2.Text + "|"; } foreach (string split2 in text2.Split('|')) { stringList.Add(split2 + "<br/>"); SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings\["ConnectionString"\]); SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCnn; SqlCnn.Open(); SqlCmd.CommandText = "insert into test(test,id) values(@test,1)"; SqlParameter DataBaseID = new SqlParameter("@test", SqlDbType.NVarChar, 50); DataBaseID.Value = stringList.Add(split2); SqlCmd.Parameters.Add(DataBaseID); SqlCmd.ExecuteNonQuery(); SqlCnn.Close(); Bindrepeater(); }
//ignore syntax errors
This is how im inserting values in textbox into db.. but im having two textboxes how i need to insert both values at a time.. into db... thank you..
What do you mean "insert both values at a time"?
I know the language. I've read a book. - _Madmatt
-
string text1 = "";
string text2 = "";private void insertfiles()
{foreach (RepeaterItem item in Rptdescription.Items) { TextBox txt1 = (TextBox)item.FindControl("TextBox1"); TextBox txt2 = (TextBox)item.FindControl("TextBox3"); text1 += txt1.Text + "|"; text2 += txt2.Text + "|"; } foreach (string split2 in text2.Split('|')) { stringList.Add(split2 + "<br/>"); SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings\["ConnectionString"\]); SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCnn; SqlCnn.Open(); SqlCmd.CommandText = "insert into test(test,id) values(@test,1)"; SqlParameter DataBaseID = new SqlParameter("@test", SqlDbType.NVarChar, 50); DataBaseID.Value = stringList.Add(split2); SqlCmd.Parameters.Add(DataBaseID); SqlCmd.ExecuteNonQuery(); SqlCnn.Close(); Bindrepeater(); }
//ignore syntax errors
This is how im inserting values in textbox into db.. but im having two textboxes how i need to insert both values at a time.. into db... thank you..
I am going to assume that you have the same number of each of the two text boxes. First you should change your loop.
string[] box1values = text1.split('|')
string[] box3values = text1.split('|')
for (int i = 0; i < box1values.length; i++)
{}
Then you can use the index to get the values of both strings.
SqlCmd.CommandText = "insert into test(test,test2,id) values(@test,@test2,1)";
SqlParameter test1Param= new SqlParameter("@test", SqlDbType.NVarChar, 50);
test1Param.Value = box1values[i];
SqlParameter test2Param = new SqlParameter("@test2", SqlDbType.NVarChar, 50);
test2param.Value = box3values[i];
SqlCmd.Parameters.Add(test1Param);
SqlCmd.Parameters.Add(test2param);I wouldn't call the test1 param DataBaseID since it isn't the column named ID.