GridView 编辑事件获取单元格数值

我是要获取编辑之前的数值。RowEditing事件里
我用gv.Rows[e.NewEditIndex].Cells[2].Text; 总是空字符串。我的EditItemTemplate模板已经换成了DropDownList。我想用DropDownList.FindByText("xxx") 选中编辑前的数值

不需要这样啊,你应该使用绑定的方法,比如:
<asp:TemplateField HeaderText="性别" SortExpression="sex">
<EditItemTemplate>
<asp:DropDownList ID="TextBox1" runat="server" Text='<%# Bind("sex") %>'>
<asp:ListItem Value="男">男</asp:ListItem>
<asp:ListItem Value="女">女</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("sex") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
这样,你点击”编辑“按钮后,那个DropDownList里面的Text自动就是原来的值了
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-08-15
是不是少加个判断
if (e.Row.RowType == DataControlRowType.DataRow)
{
//判断是不是内容行,是的话再进判断
}

我是从“上海全鼎软件学院”毕业的————————
第2个回答  2011-08-15
dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString()
相似回答