Search code examples
c#asp.netdevexpressaspxgridviewautopostback

how to get selected row from DevExp AspxGridview


I am trying to get the selected row from the aspxgridview when the user clicks the "SEÇ"("SELECT") button on screen as shown below.

when the user click the SEC button, it gives null reference exception

What am doing wrong?

here is my code...

protected void btnClose0_Click(object sender, EventArgs e)
    {
        try
        {
            string cari_logref = gvCari.GetDataRow(gvCari.FocusedRowIndex)["LOGICALREF"].ToString();

            dtneww = ListTable(Convert.ToInt16(cari_logref));
            gv.DataSource = dtneww;
            gv.DataBind();
        }
        catch (Exception)
        { }
    }

enter image description here


Solution

  • You are attempting to retrieve the focused row with FocusedRowIndex, what you want is GetSelectedFieldValues which is different, see: https://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_GetSelectedFieldValuestopic