| Author: Pannalal Sinha 06 Nov 2009 | Member Level: Gold | Rating:  Points: 2 |
When creating the textboxes dynamically, provide names to each one e.g., TextBox1, TextBox2, TextBox3, TextBox4.
In the save button click event handler, use this names...
strQuery="Insert into table1 (col1,col2,col3,col4) values ('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"')"
Thanks Panna
|
| Author: sirisha 06 Nov 2009 | Member Level: Silver | Rating:  Points: 2 |
Hello Sinha. Thans for ur quick reply. I have given name for 1st textbox as TxtName. When i try to use this in the query, its giving me an error saying that it is not declared.
|
| Author: Pannalal Sinha 07 Nov 2009 | Member Level: Gold | Rating:  Points: 2 |
you can generate dynamic textbox like this.
TextBox TextBox1= new TextBox(); TextBox1.Name = "TxtName"; this.flowLayoutPanel2.Controls.Add(TextBox1);
//now you can use it in your query
Thanks Panna
|
| Author: sirisha 07 Nov 2009 | Member Level: Silver | Rating:  Points: 2 |
I have added everything according to your suggestions.But still in the insert query
strQuery="Insert into table1 (col1,col2,col3,col4) values ('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"')"
it insists me saying that textbox1,textbox2,textbox3,textbox4 is not declared
|
| Author: Pannalal Sinha 07 Nov 2009 | Member Level: Gold | Rating:    Points: 6 |
sorry i was wrong little bit.
I assume you are adding the textboxes in a flowlayoutpanel. Then
void savebutton_click() { string value1=""; string value2=""; string value3=""; string value4="";
for(int i=0;i<flowLayoutPanel2.Controls.Count;i++) { switch(flowLayoutPanel2.Controls[i].Name) { case "TextBox1": value1=flowLayoutPanel2.Controls[i].Text; Break;
case "TextBox2": value2=flowLayoutPanel2.Controls[i].Text; Break;
case "TextBox3": value3=flowLayoutPanel2.Controls[i].Text; Break;
case "TextBox4": value4=flowLayoutPanel2.Controls[i].Text; Break; }
} strQuery="Insert into table1 (col1,col2,col3,col4) values ('"+value1+"','"+value2+"','"+value3+"','"+value4+"')"
}
|
| Author: sirisha 07 Nov 2009 | Member Level: Silver | Rating:  Points: 2 |
ThankU so much Sinha. It worked.But i am still going to trouble u. I used the flow layout panel. How to set the controls position in this.
|
| Author: Pannalal Sinha 07 Nov 2009 | Member Level: Gold | Rating:  Points: 2 |
Sirisa, FlowLayOutPanel doesn't provide the facility of positioning the controls at a specific location. However,it has Flow Direction property which can be used according to your requirement.
I recommend you to visit the following links.
http://www.yevol.com/en/vcsharp/controls/flowlayoutpanel.htm http://msdn.microsoft.com/en-us/library/z9w7ek2f(VS.80).aspx
Thanks Panna
|