Tuesday, June 28, 2022

Gridview boundfield find by datafield name ASP.NET C# on grid rowupdaing event

 private int FindIndexByDataField(GridView gv, string datafieldname)

    {

        int index = -1, cnum = 0;

        foreach (DataControlField col in gv.Columns)

        {

            if (col is BoundField)

            {

                BoundField coll = (BoundField)gv.Columns[cnum];

                if (coll.DataField == datafieldname)

                {

                    index = cnum;

                    break;

                }

            }

            cnum++;

        }

        return index;

    }


protected void grd_Invoice_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

tpUpdateBy = grd_Invoice.Rows[e.RowIndex].Cells[FindIndexByDataField(grd_Invoice, "I_TP_UpdateBy")].Text;

}


reference :- https://stackoverflow.com/questions/35795278/how-to-get-boundfield-value-of-a-gridview-in-rowupdating-event

https://stackoverflow.com/questions/46489882/how-can-i-find-a-boundfield-inside-a-gridview-by-datafield

No comments:

Post a Comment