What do you need help with what exactly? Writing SQL? Are you having trouble designing dynamic inputs?
I want to mention, Web Forms come with data bound controls which are APIs specifically designed to render dynamic controls and handle updates through a standard event handler interface.
Anyway, if you share your code and explain the problem you are trying to solve then community will be in a better position to provide assistance.
Just i need help to get controls value before inserting data into sql.
How to get row by row data from TableLayoutPanel?
Excel OpenExcel 1 2
Browser KillUrl 3 4
string[] datatxt = new string[this.TableLayoutPanel1.Controls.Count];
string[] datacb = new string[3];
for (int r = 0; r < TableLayoutPanel1.RowCount; r++)
{
for (int i = 0; i < this.TableLayoutPanel1.Controls.Count; i++)
{
if (this.TableLayoutPanel1.Controls[i] is TextBox)
{
TextBox txtserial = (TextBox)this.TableLayoutPanel1.Controls[i];
string value = txtserial.Text;
datatxt[i] += value;
value = "";
}
if (this.TableLayoutPanel1.Controls[i] is ComboBox)
{
ComboBox cbserial = (ComboBox)this.TableLayoutPanel1.Controls[i];
string value = cbserial.Text;
datacb[i] += value;
value = "";
}
}
When you decided to create dynamic controls then you lost the standard state management feature in .NET Web Forms. That makes sense, right, because there no record of the dynamic controls in the page markup or designer file. The framework has no idea the
controls exist when the page loads. It is up to you to write code that adds the expected dynamic controls early in the page life cycle. This will allow the framework to bind the post values to the controls. You did not post state management code so I have
no idea if you you've written the code or not. I think it is important to understand that dynamic controls in Web Forms is a very mature subject and a quick Google search will turn up many tutorials and blogs. Even the FAQs on this forum covers this programming
pattern.
With that being said, I recommend using standard data bound controls rather than dynamic controls.
You can try below code, you can use the TableLayoutPanel.
GetControlFromPosition method returns the child control occupying the specified position.
for (int i = 0; i < tableLayoutPanel1.RowCount; i++)
{
for (int j = 0; j < tableLayoutPanel1.ColumnCount; j++)
{
Control c = this.tableLayoutPanel1.GetControlFromPosition(i, j);
Console.Write(((TextBox)c).Text);
}
Console.WriteLine();
}
Best regards,
Sam
IIS.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
for (int i = 0; i <= this.TableLayoutPanel1.RowCount; i++)
{
string[] datatxt = new string[this.TableLayoutPanel1.ColumnCount];
for (int j = 0; j <= this.TableLayoutPanel1.ColumnCount; j++)
{
Control c = this.TableLayoutPanel1.GetControlFromPosition(j, i);
Do you solve the problem? If not, please explain your problem in detail.
Best regards,
Sam
IIS.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
39 Points
109 Posts
Save row by row data of TableLayoutPanel in sql
Jun 04, 2020 12:40 PM|Neeraj Yadav|LINK
Hi all,
I have created dynamic control in TableLayoutPanel and there are multiple rows in TableLayoutPanel.
Now i want to save one by one row data of these control like textbox, combobox into database which are generated dynamic .
Please help on this.
All-Star
53641 Points
24005 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 04, 2020 12:49 PM|mgebhard|LINK
What do you need help with what exactly? Writing SQL? Are you having trouble designing dynamic inputs?
I want to mention, Web Forms come with data bound controls which are APIs specifically designed to render dynamic controls and handle updates through a standard event handler interface.
Anyway, if you share your code and explain the problem you are trying to solve then community will be in a better position to provide assistance.
Member
39 Points
109 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 04, 2020 01:53 PM|Neeraj Yadav|LINK
Just i need help to get controls value before inserting data into sql.
How to get row by row data from TableLayoutPanel?
Excel OpenExcel 1 2
Browser KillUrl 3 4
string[] datatxt = new string[this.TableLayoutPanel1.Controls.Count];
string[] datacb = new string[3];
for (int r = 0; r < TableLayoutPanel1.RowCount; r++)
{
for (int i = 0; i < this.TableLayoutPanel1.Controls.Count; i++)
{
if (this.TableLayoutPanel1.Controls[i] is TextBox)
{
TextBox txtserial = (TextBox)this.TableLayoutPanel1.Controls[i];
string value = txtserial.Text;
datatxt[i] += value;
value = "";
}
if (this.TableLayoutPanel1.Controls[i] is ComboBox)
{
ComboBox cbserial = (ComboBox)this.TableLayoutPanel1.Controls[i];
string value = cbserial.Text;
datacb[i] += value;
value = "";
}
}
All-Star
53641 Points
24005 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 04, 2020 03:08 PM|mgebhard|LINK
When you decided to create dynamic controls then you lost the standard state management feature in .NET Web Forms. That makes sense, right, because there no record of the dynamic controls in the page markup or designer file. The framework has no idea the controls exist when the page loads. It is up to you to write code that adds the expected dynamic controls early in the page life cycle. This will allow the framework to bind the post values to the controls. You did not post state management code so I have no idea if you you've written the code or not. I think it is important to understand that dynamic controls in Web Forms is a very mature subject and a quick Google search will turn up many tutorials and blogs. Even the FAQs on this forum covers this programming pattern.
With that being said, I recommend using standard data bound controls rather than dynamic controls.
Member
39 Points
109 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 04, 2020 03:45 PM|Neeraj Yadav|LINK
have we any TableLayoutPanel control in asp.net?
I am looking code for window app using c#
All-Star
53641 Points
24005 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 04, 2020 04:48 PM|mgebhard|LINK
You are in the wrong forum. This is an ASP.NET support forum for building web site. You need a Windows App support forum.
https://social.msdn.microsoft.com/Forums/windows/en-US/home?category=windowsforms
Member
39 Points
109 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 05, 2020 05:15 AM|Neeraj Yadav|LINK
Thanks for support
Contributor
3370 Points
1409 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 05, 2020 06:10 AM|samwu|LINK
Hi Neeraj Yadav,
You can try below code, you can use the TableLayoutPanel. GetControlFromPosition method returns the child control occupying the specified position.
Best regards,
Sam
Member
39 Points
109 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 08, 2020 05:25 AM|Neeraj Yadav|LINK
Final Code for the same requirement.
for (int i = 0; i <= this.TableLayoutPanel1.RowCount; i++)
{
string[] datatxt = new string[this.TableLayoutPanel1.ColumnCount];
for (int j = 0; j <= this.TableLayoutPanel1.ColumnCount; j++)
{
Control c = this.TableLayoutPanel1.GetControlFromPosition(j, i);
if (c != null)
{
Console.WriteLine(c.Text);
string value = c.Text;
if ((value != "+") && (value != "-"))
{
datatxt[j] += value;
}
}
}
if (datatxt[0] != null)
{
string strquery = "insert into tblMaster(a,b,c,d) values('" + datatxt[0] + "','" + datatxt[1] + "','" + datatxt[2] + "','" + datatxt[3] + "')";
con.Open();
cmd = new SqlCommand(strquery, con);
cmd.ExecuteNonQuery();
con.Close();
}
datatxt = null;
}
Contributor
3370 Points
1409 Posts
Re: Save row by row data of TableLayoutPanel in sql
Jun 08, 2020 09:42 AM|samwu|LINK
Hi Neeraj Yadav,
Do you solve the problem? If not, please explain your problem in detail.
Best regards,
Sam