获取前台gridview上的可编辑字段内容
问个问题,前台页面上用gridview创建了一个列表,现在后台想获取其中的可编辑字段,要如何处理?
<asp:TemplateField HeaderText="发货日期">
<ItemStyle Width="120px"></ItemStyle>
<ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="deliveryDate" text='<%#Bind("发货日期")%>' runat="server">
</asp:TextBox>
</EditItemTemplate>
</ItemTemplate>
</asp:TemplateField>
在每行记录最后都有个button,传递数据。但是可编辑文本内容无法获取。
<asp:TemplateField HeaderText="下发指示书">
<ItemStyle Width="60px"></ItemStyle>
<ItemTemplate>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" CommandArgument='<%# ((System.Data.DataRowView)Container.DataItem)["机号"]+","+((System.Data.DataRowView)Container.DataItem)["纳入国"]+","+((System.Data.DataRowView)Container.DataItem)["客户名称"]%>' Text="下发" />
</ItemTemplate>
</asp:TemplateField>
我在网上查询,看有的人使用onRowCommand来获取,但我仿照写的程序并不成功。g.Cells[6].Text的值一直为空字符串。
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
string deliveryDate = "";
Control c = (Control)e.CommandSource;
GridViewRow g = (GridViewRow)c.NamingContainer;
deliveryDate = g.Cells[6].Text;
}