Click here to Skip to main content
15,886,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm trying to create a form where the user gives number to generate textboxes. when for example the user enters 3 into textbox, three text boxes get generated in the new frame. now when the user write data into these text boxes I want it to be saved in SQL database. Anybody please help me into this.

My Code goes here:

C#
protected void btnsubmit_Click(object sender, EventArgs e) 
{ 
	DataTable tab = new DataTable(); 
	tab = obj.RetrieveId(); 
	int id = Convert.ToInt32(tab.Rows[0]["Order_Id"].ToString()); 
	for (int i = 0; i < Convert.ToInt32(txtorders.Text); i++) 
	{ 
		string txtvalue = "mytxt" + i.ToString(); 
		TextBox txt = (TextBox)pnlText.FindControl(txtvalue); 
		if (txt != null) 
		{ 
			string strText = txt.Text; 
			obj.saveDetails(id, strText); // (SaveDetails is a Function to save values to SQL which i have written in class) 
		} 
	}
}
Posted
Updated 25-Sep-13 1:54am
v2
Comments
Maciej Los 25-Sep-13 4:47am    
Which part exactly?
[no name] 25-Sep-13 5:15am    
i need to retrieve values from the textboxes and save it in Database
Maciej Los 25-Sep-13 5:18am    
I know what you want. I'm asking you: where are you stuck? what have you done till now?
Please, improve your question (shortly describe your problem) and paste relevant code (do not forget to use formatting).
[no name] 25-Sep-13 5:23am    
protected void btnsubmit_Click(object sender, EventArgs e)
{
DataTable tab = new DataTable();
tab = obj.RetrieveId();
int id = Convert.ToInt32(tab.Rows[0]["Order_Id"].ToString());
for (int i = 0; i < Convert.ToInt32(txtorders.Text); i++)
{
string txtvalue = "mytxt" + i.ToString();
TextBox txt = (TextBox)pnlText.FindControl(txtvalue);
if (txt != null)
{
string strText = txt.Text;
obj.saveDetails(id, strText); // (SaveDetails is a Function to save values to SQL which i have written in class)
}
}
Maciej Los 25-Sep-13 5:26am    
Use "Improve question" widget.

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