双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

获取前台gridview上的可编辑字段内容

zhengoodman zhengoodman 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

问个问题,前台页面上用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;

}
...全文
评论 4
收藏 已收藏
分享
返回顶部
zhengoodman
.NET社区 62,274 成员 668,968 内容