How to get the cell value by column name not by index in GridView in asp.net

后端 未结 10 1613
轻奢々
轻奢々 2020-12-01 06:21

I am having a gridview in asp.net and now I want the cell value by the column name but not by the cell index.

How would be it possible

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 06:34

    //get the value of a gridview
    public string getUpdatingGridviewValue(GridView gridviewEntry, string fieldEntry)
        {//start getGridviewValue
            //scan gridview for cell value
                string result = Convert.ToString(functionsOther.getCurrentTime()); 
                for(int i = 0; i < gridviewEntry.HeaderRow.Cells.Count; i++)
                    {//start i for
                        if(gridviewEntry.HeaderRow.Cells[i].Text == fieldEntry)
                            {//start check field match
                                result = gridviewEntry.Rows[rowUpdateIndex].Cells[i].Text;
                                break;
                            }//end check field match
                    }//end i for
            //return
                return result;
        }//end getGridviewValue
    

提交回复
热议问题