如何从boundfield获取值,然后将其传递到itemtemplate字段



这里我很难从绑定字段到模板字段获取值。。

            <asp:CommandField ShowSelectButton="True" />

            <asp:BoundField HeaderText="productid" DataField="productid" 
                SortExpression="productid" />
            <asp:BoundField HeaderText="categoryid" DataField="categoryid" 
                SortExpression="categoryid" />
        <asp:BoundField HeaderText="productname" DataField="productname" 
                SortExpression="productname" />
        <asp:BoundField HeaderText="unitsinstock" DataField="unitsinstock" 
                SortExpression="unitsinstock" />
        <asp:TemplateField>
        <ItemTemplate>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        </ItemTemplate>
        </asp:TemplateField>
        </Columns>

这是我的代码:

protected void GridView1_RowEditing(对象发送方,GridViewEditEventArgs e){

    TextBox text_ref = (TextBox)GridView1.Rows[e.NewEditIndex].Cells[3].FindControl("TextBox2");

}

在这里,当用户单击gridview中的编辑链接时,边界字段值应该转移到项目模板内的文本框控件。

但上面的代码不起作用。如何做到这一点?如何解决这个问题?

尝试调试代码并检查运行时值。您的代码似乎是正确的,但请确保单元格索引(代码中的3)是模板控件所属的单元格:对我来说,这是可疑的部分。

最新更新