如何在另一个控件l中获取动态文本框ID? [英] How to get Dynamic textbox id in another control l?
本文介绍了如何在另一个控件l中获取动态文本框ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用动态文本框时遇到问题,
我有14个动态文本框的gridview,我需要将这些值插入数据库中,而我的问题是如何将这些动态文本框id放入Button中
Hi,
I have a problem with Dynamic Textbox,
I have gridview with 14 dynamic textboxes,and i need to insert those values into database ,and my problem is how to get those dynamic textboxes id''s into Button
private TextBox CreateTextBox(GridViewRow row,int i)
{
TextBox txtint = new TextBox();
txtint.Width = 25;
txtint.Text = "0";
txtint.ID = "txtint" + row.RowIndex + i.ToString();
txtint.TextChanged += new EventHandler(txtint_TextChanged);
//txtint.Attributes.Add("onBlur", "Addition('" + txtint.ID + "');");
txtint.Attributes.Add("onBlur", "Addition();");
txtint.Attributes.Add("onkeyup", "Average();");
// this.Page.Controls.Add(txtint);
return txtint;
}
}
推荐答案
迭代控件
foreach (Control ctrl in Page.Controls)
{
if (ctrl is TextBox)
{
Textbox myTextBox = (TextBox)ctrl;
// read the ID in myTextBox.ID
// based on ID you know which parameter should have the value from the Text property
}
}
按钮单击事件
In Button Click event
foreach (GridViewRow row in myGridView.Rows)
{
TextBox txtbox = (TextBox)row.FindControl("txtint" + row.RowIndex.ToString());
}
您需要更改"txtint.ID ="txtint" + row.RowIndex + i.ToString()
到
txtint.ID ="txtint" + row.RowIndex;
希望这会有所帮助!
You need to change "txtint.ID = "txtint" + row.RowIndex + i.ToString()
to
txtint.ID = "txtint" + row.RowIndex;
Hope this helps!
这篇关于如何在另一个控件l中获取动态文本框ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文