【问题标题】:find Countrol inside itemTemplate of Gridview without Gridview Events在没有 Radgridview 事件的 Gridview 的 dataTemplate 中找到控件
【发布时间】:2014-05-30 15:27:14
【问题描述】:

我在 Gridview 的 ItemTemplate 中有一个文本框。我需要在不使用 RowDatabound 或任何其他 Gridview 事件的情况下找到该文本框

aspx

<asp:GridView ID="gv_Others" runat="server" AutoGenerateColumns="false">
                    <Columns>
                    <asp:TemplateField >                        
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemTemplate >                     
                            <asp:TextBox ID="txtEmp" runat="server" Width=100% Height=22px CssClass="input"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    </Columns>
                </asp:GridView> 

aspx.cs

protected void Insert_OtherServices()
    {
        dsJobCardTableAdapters.Select_OtherServiceTableAdapter dsother = new dsJobCardTableAdapters.Select_OtherServiceTableAdapter();
        int count = 0;
        foreach (GridViewRow row in gv_Others.Rows)
        {
            //string b = (row.Cells[0].Controls[0] as DataBoundLiteralControl).Text;
            //TextBox a = gv_Others.Rows[count].Cells[0].FindControl("txtEmp") as TextBox;
           // string test = a.Text;
            //TextBox other = (TextBox)gv_Others.Rows[count].FindControl("txtEmp");
            TextBox other = (TextBox)gv_Others.TemplateControl.FindControl("txtEmp");
            dsother.Insert_OtherService(other.Text);
            count++;
        }
    } 

是否有任何替代方法可以从 Gridview 的项目模板内的文本框中获取值

【问题讨论】:

    标签: c# jquery asp.net gridview


    【解决方案1】:

    您的意思是要查找文本框值而不遍历 GridView 行吗?如果是这种情况,可以使用 jQuery/javascript 来实现。

    1. 读取客户端上的所有文本框值。您可以找到有关如何执行此操作的更多信息here
    2. 使用隐藏字段将这些值与回发请求一起传递。读取并使用方法中的隐藏字段值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多