簡體   English   中英

如何獲取單元格的值指定GridView ASP.NET

[英]How to get the value of a cell specifies the GridView ASP.NET

我需要獲取GridView單元格的值。 當用戶單擊網格時,我需要知道哪個行按鈕,然后獲取單元格的值。 我正在嘗試使用以下代碼,但無法正常工作。

 protected void gvSearch_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            int row = Convert.ToInt32(e.CommandArgument);

            string tst = gvSearch.Rows[row].Cells[1].Text;
        }
    }

我不知道我是否在使用正確的事件來實現自己的目標。 如果有人可以幫助我,謝謝。

我找到了解決方案!

我正在使用BoundField。

<asp:BoundField HeaderText="Código Área" DataField=" <asp:BoundField HeaderText="Denominação Área" DataField="areaName" />

protected void gvSearch_SelectedIndexChanged(object sender, EventArgs e)
    {
        String lastName = gvSearch.SelectedRow.Cells[1].Text;
    }

感謝大家!

您可以使用此代碼

protected void gvSearch_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        string pc = gVSearch.Rows[int.Parse(e.CommandArgument.ToString())].Cells[1].Text;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM