在Gridview控件中使用模板列显示数据,在GridView1_RowEditing事件中怎样在后台获取itemtemplate中编辑之前的数据?
<asp:GridView ID="GridView1" runat="server" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:TemplateField HeaderText="入库数量"> <ItemTemplate> <asp:Label ID="rukunum" runat="server" Text='<%# Eval("rukunum") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="Trukunum" Text='<%# Eval("rukunum") %>' runat="server" Font-Size="8" Width="55px" /> </EditItemTemplate> <ItemStyle Width="70px" /> </asp:TemplateField> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" HeaderText="操作" /> </Columns> </asp:GridView>
加一个TextBox 来保存更改前的数据, 控件是隐藏的。
<EditItemTemplate> <asp:TextBox ID="Trukunum" Text='<%# Eval("rukunum") %>' runat="server" Font-Size="8" Width="55px" />
<asp:TextBox ID="hdTrukunum" style="display:none"
Text='<%# Eval("rukunum") %>' runat="server" Font-Size="8"
Width="55px" />
</EditItemTemplate>
TEXTBOX tb= (Textbox)e.Row.FindControl("rukunum");