网格视图绑定域问题 [英] Grid view Bound Fields Problem
本文介绍了网格视图绑定域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题我已将gridview页面放在aspx页面中,我想在单击编辑按钮时获取绑定字段的值.
我在编辑按钮上写了以下代码
Questioni have put gridview page in aspx page i want to get value of bound field when click on edit button.
i have write below code on edit button
protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gvRow = gv1.Rows[e.RowIndex];
string Name = gvRow.Cells[1].Text;
}
gvRow.Cells [1].文本重新运行",插入值
gvRow.Cells[1].Text retrun "" insted of value
<asp:GridView ID="gv1" runat="server" EmptyDataText="No Record Found"
Width = "100%" AllowPaging="True" PageSize="2"
onpageindexchanging="gv1_PageIndexChanging" AutoGenerateColumns="False"
AllowSorting="true" onrowediting="gv1_RowEditing"
AutoGenerateEditButton="true" onrowupdating="gv1_RowUpdating" DataKeyNames="Name">
<Columns>
<asp:BoundField AccessibleHeaderText="Name" HeaderText = "Name"
ItemStyle-Wrap="true" DataField="Name" InsertVisible="true">
<HeaderStyle Font-Size="Large" Wrap="false" />
<FooterStyle ForeColor="Yellow" />
<ItemStyle Font-Italic="true" BackColor="ActiveBorder" Font-Size="Large" />
</asp:BoundField>
<asp:BoundField HeaderText="Amount" DataField="Amount"
ConvertEmptyStringToNull="false" DataFormatString="{0:C}"/>
</Columns>
</asp:GridView>
推荐答案
尝试一下,它将起作用.
Try this, it will works.
protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gvRow = gv1.Rows[e.RowIndex];
string Name = ((TextBox) gvRow.Cells[1].Controls[0]).Text;
}
或
Or
protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string Name = ((TextBox) gv1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
}
这篇关于网格视图绑定域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文