我如何读取动态创建的文本框(gridview OnRowUpdating) [英] How can I read a dynamically created textbox (gridview OnRowUpdating)
本文介绍了我如何读取动态创建的文本框(gridview OnRowUpdating)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< asp:GridView ID =GridView1runat =server>
< asp:TemplateField HeaderText =TokenSortExpression =TokenHeaderStyle-Width =100px>
< ItemTemplate>
< / ItemTemplate>
< / asp:TemplateField>
< / asp:GridView>
更新:
ctl00_ContentPlaceHolder1_tabControl_tabUsers_MyControl1_gv_ctl02__token0_3
页面的源代码是我所看到的文本框的id。
OnRowUpdating:
TextBox _token = gvOrg.Rows [e.RowIndex] .Cells [7] .FindControl(_ token+ e.RowIndex +_+ rowId)作为TextBox;
更新结束:
这里是我的代码:
< pre $
protected void gv_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
for(int rowId = 0; rowId< 5; rowId ++)
{$ b Text TextBox _token = gvOrg.Rows [e.RowIndex] .Cells [7] .FindControl(_ token+ rowId)作为TextBox;
protected void gv_RowDataBound(object sender,GridViewRowEventArgs e)
{
if((e.RowState ==(DataControlRowState。编辑| DataControlRowState.Alternate))||(e.RowState == DataControlRowState.Edit))
{
if(e.RowType == DataControlRowType.DataRow)
$ b {
for(int rowId = 0; rowId< 5; rowId ++)
{
TextBox txtBox = new TextBox();
txtBox.ID =_token+ rowId;
txtBox.Text =token+ rowId;
e.Row.Cells [7] .Controls.Add(txtBox);
$ div $解析方案
是我如何解决这个问题:而不是创建rowdatabound我创建的RowCreated,希望这将有助于其他人。
protected void gridviwe1_RowCreated(object sender,GridViewRowEventArgs e)
{
if(e.RowType == DataControlRowType.DataRow)
{
for(int rowId = 0; rowId< 5; rowId ++)
{
TextBox txtBox = new TextBox();
txtBox.ID =_registration+ e.Row.RowIndex +_+ rowId;
txtBox.Text =_registration+ e.Row.RowIndex +_+ rowId;
e.Row.Cells [7] .Controls.Add(txtBox);
}
}
}
<asp:GridView ID="GridView1" runat="server" >
<asp:TemplateField HeaderText="Token" SortExpression="Token" HeaderStyle-Width="100px">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
update:
after i view the source code of the page thsi is what i see the id of a textbox that i have created dynamic.
ctl00_ContentPlaceHolder1_tabControl_tabUsers_MyControl1_gv_ctl02__token0_3
OnRowUpdating:
TextBox _token = gvOrg.Rows[e.RowIndex].Cells[7].FindControl("_token " + e.RowIndex + "_" + rowId) as TextBox;
Update end:
i am adding few textbox dynamic in OnRowDataBound and whe i try getting the value then i am getting null
here is my code:
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
for (int rowId = 0; rowId < 5; rowId++)
{
TextBox _token = gvOrg.Rows[e.RowIndex].Cells[7].FindControl("_token" + rowId) as TextBox;
}
}
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)) || (e.Row.RowState == DataControlRowState.Edit))
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int rowId = 0; rowId < 5; rowId++)
{
TextBox txtBox = new TextBox();
txtBox.ID = "_token" + rowId;
txtBox.Text = "token" + rowId;
e.Row.Cells[7].Controls.Add(txtBox);
}
}
解决方案
here is how i able to fix the problem: instead of creating in rowdatabound i am creating on RowCreated, hope this will help others.
protected void gridviwe1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int rowId = 0; rowId < 5; rowId++)
{
TextBox txtBox = new TextBox();
txtBox.ID = "_registration" + e.Row.RowIndex + "_" + rowId;
txtBox.Text = "_registration" + e.Row.RowIndex + "_" + rowId;
e.Row.Cells[7].Controls.Add(txtBox);
}
}
}
这篇关于我如何读取动态创建的文本框(gridview OnRowUpdating)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文