日期:2014-05-18  浏览次数:20500 次

如何获取GridView当前选中的记录的某个字段的值?
希望给出一个具体一点的例子

------解决方案--------------------
up
GridView1.Rows[GridView1.SelectedIndex].FindControl("控件名字");
------解决方案--------------------
HTML code
<asp:GridView ID="GridView1" runat="server" DataKeyNames="id" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
    </Columns>
</asp:GridView>

------解决方案--------------------
C# code

//非编辑状态
string signName = this.gvSignUp.Rows[e.RowIndex].Cells[0].Text.Trim();
//编辑状态
string realCharge = ((TextBox)this.gvSignUp.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim();

------解决方案--------------------
如果用的简单绑定GridView1.SelectedRow.Cells[0].Text
如果用的模版列,里面放了控件,要获取控件值
TextBox b = (TextBox)(GridView1.SelectedRow.FindControl("textbox1"));
string aa = b.Text;