当前位置:编程学习 > C#/ASP.NET >>

急问!请问如何在Datagrid中查找模版列中的TextBox控件的ID?

页面代码:
<asp:TemplateColumn>
   <HeaderStyle Width="100" />
     <HeaderTemplate>
<asp:TextBox ID="dtg_00_ProdCode" runat="server" BackColor="transparent" ForeColor="white" ToolTip="dtg_00_ProdCode" BorderStyle="none" ReadOnly="true" Text="dtg_00_ProdCode" Width="100%"></asp:TextBox>
 </HeaderTemplate>
 </asp:TemplateColumn>

如何在后台程序中获得上述TextBox控件的ID值,即“dtg_00_ProdCode”?
敬请高人指点! --------------------编程问答-------------------- ((TextBox)e.Item.Cells[i].Controls[0]).ID
--------------------编程问答-------------------- protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Header)
        {
            Response.Write(((TextBox)e.Item.Cells[0].Controls[1]).ID);
        }
    }
--------------------编程问答-------------------- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TextBox tb = (TextBox)this.GridView1.FindControl("TextBox1");
            Response.Write("'"+tb.Text+"'");
        }
    } --------------------编程问答-------------------- //按鈕裡讀取
protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox TextBox1 = (TextBox)DataGrid1.FindControl("dtg_00_ProdCode");
        Response.Write("'" +TextBox1.Text + "'");
    } --------------------编程问答-------------------- cpp2017(慕白兄) 
是对的!支持 --------------------编程问答-------------------- 超级简单的问题。
foreach (DataListItem dl in this.DataList1.Items)
        {         
           string date = ((TextBox)dl.FindControl("TextBox1")).ID;
                           
       } --------------------编程问答-------------------- 谢谢慕白兄的回复,我现在想实现的功能是查出页面上所有的控件,对于页面上其他控件,比如:TextBox,Label等都已获得,就是对于datagrid中模版列中的控件不知如何得到,我现在将我的后台部分代码粘上开,麻烦帮我看看应该如何写?
 public void InitSystemTranslation(System.Web.UI.Page obj)
        {
            HtmlForm form = new HtmlForm();
            
            for (int i = 0; i < obj.Controls.Count; i++)
            {
                if (obj.Controls[i] is HtmlForm)
                {
                    form = obj.Controls[i] as HtmlForm;
                }
            }
        foreach (object obj1 in form.Controls)
            {
                if (obj1 is Panel)
                {
                    foreach (object obj2 in (obj1 as Panel).Controls)
                    {
                        if (obj2 is Button)
                        {
                            Button Btn = obj2 as Button;
                        }
                        else if (obj2 is DataGrid)
                        {
                            DataGrid Dtg = obj2 as DataGrid;

                            if (Dtg.ID.Length > 4 && Dtg.ID.Substring(Dtg.ID.Length - 4) == "Head")
                            {
                                //如何写?
                            }
                        }
                        else if (obj2 is Label)
                        {
                            Label Lbl = obj2 as Label;

                        }
                    }
                }
            }
        }
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,