GridView外的按钮

时间:2015-07-15 18:43:22

标签: c# visual-studio-2010

1 - 在GridView中有GridView和一个按钮

2 - 如何使用按钮

从此网格中获取特定值

.aspx的:

<asp:GridView ID="gvCalc" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="tx_desc" />
    </Columns>
</asp:GridView>

<asp:Button ID="btnGetValue" runat="server" OnClick="btnGetValue_Click" />
<asp:Label ID="lbError" runat="server"></asp:Label>

C#:

protected void btnGetValue_Click(object sender, EventArgs e)
{
    lbError.Text = gvCalc.Rows[0].Cells[0].ToString(); 
    //lbError RETURNS 'System.Web.UI.WebControls.DataControlFieldCell' 
    //I DONT WANT THAT...I WANT THE VALUE
}

1 个答案:

答案 0 :(得分:0)

TableCell有一个属性Text,其中包含Cell的内容。

使用

grd.Rows[0].Cells[0].Text;

而不是

grd.Rows[0].Cells[0].ToString();
相关问题