GridViewRowEventArgs access cells without the index?


  • On my

    protectedvoidgridView_RowDataBound(objectsender, GridViewRowEventArgse)

    I would like to access my cell without an index, because it looks ugly.


    e.Row.Cells[2].Text is not good.

    I would like to use my column name, is that possible?

    2012년 2월 28일 화요일 오후 7:16


모든 응답

  • Sure. One or the other (index or column name):



    2012년 2월 28일 화요일 오후 7:26
  • Just use double quotes on both sides of column name, so its presented like a stirng.


    2012년 2월 28일 화요일 오후 7:27
  • Thanks but I don't think it accepts string, it says - The best overloaded method for System.Web.UI.WebControls.TableCollectionTable.this[int] has some invalid arguments
    2012년 2월 28일 화요일 오후 7:33
  • Iam not sure how is for web table. I guess you will have to use indexes after all. Sorry.


    2012년 2월 28일 화요일 오후 8:27
  • Hi PrivatePyle1982,

    Welcome to the MSDN forum.

    You can use the .Ordinal property of the DataTable's column to return the index that would correspond to the index of a cell displayed in the GridView. You can check the below link.
    Reference GridView Cells Using Column Names

    In addition, for ASP.NET issue you can consider posting it at the following more appropriate forum for more efficient responses. Thanks.

    Have a nice day.

    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    • 답변으로 표시됨 PrivatePyle1982 2012년 3월 5일 월요일 오후 3:11
    2012년 3월 1일 목요일 오전 8:52