动态控件ID未触发 [英] Dynamic control id is not firing

查看:65
本文介绍了动态控件ID未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有gridview和按钮输出。对于gridview我有自动生成列true它是dynamicllay根据角色更改所以不同的网格将出现。我将绑定网格结构如下(注意它可能会根据角色变化)



Hi ,

I have gridview and button out side. for gridview i have autogenerate columns true it was dynamicllay change as per the roles so different grids will appear.i will bind the grid structure as follows(note it might chage as per the roles)

SNo  Name     Address
1    kerrthi   hyderabad



i我在标签和行数据中显示gridview i正在做什么


i am showing the gridview in label and in row data bound i was doing

TextBox tb = new TextBox();
RequiredFieldValidator rfv = new RequiredFieldValidator();
tb.Text = string.Empty;
if (grvInsuranceDetails.HeaderRow.Cells[i].Text == "IE_VECHICLE_MAP") { 
    tb.Enabled = false;
    tb.Text = ViewState["IE_Vehiclecode"].ToString();
}
tb.ID = "txtbox" + i.ToString();
rfv.ID = "rfvvalid" + i.ToString();
rfv.ControlToValidate = tb.ID;
rfv.ErrorMessage = "*";
rfv.ForeColor = System.Drawing.Color.Red;
rfv.ValidationGroup = "required";
tb.Style.Add("Width", "120px");
tb.Style.Add("Height", "15px");
tb.Attributes.Add("runat", "Server");
//c.Controls.Clear();
//c.RowSpan
grdviewvechicleDetails.Controls.Add(tb);
c.Controls.Add(tb);
c.Controls.Add(rfv);
i++;





在提交按钮中单击我无法找到它显示为null的文本框ID





in submit button click i was not able the find the text box id it was showing as null

foreach (GridViewRow grv in grvInsuranceDetails.Rows)
            {
                int i = 0;
                   TextBox txt = (TextBox)grv.FindControl("txtbox1");
                    foreach (TableCell c in grv.Cells)
                    {
                        TextBox txt1 = (TextBox)c.FindControl("txtbox0");
                        string grdid = grvInsuranceDetails.Rows[grv.RowIndex].Cells[i].Text.ToString().TrimEnd();
                        i++;
                    }
            } 





有人可以帮我吗?



在此先感谢!



Can anybody help me with this?

Thanks in advance!

推荐答案

您是在回发时(以及点击事件触发之前)重新绑定GridView吗?如果不这样,动态添加的控件将不会成为控件树的一部分,并且FindControl将无法找到它们。
Are you rebinding the GridView on postback (and prior to the click event firing)? The dynamically added controls won't be a part of the control tree if you don't and FindControl won't be able to find them.


这篇关于动态控件ID未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆