0

I am creating GridView by creating DataTable and setting it as a Datasource of GridView, similar to

add new row in gridview after binding C#, ASP.net

After calling DataBind() I cannot access values of the cells as Text attribute is empty for every cell, however everything is displayed on the page.

I have already tried:

How to get cell value from a gridview?

but Text attribute is also empty, and

How to get cell value in GridView (WITHOUT using cell index)

throws exception as DataItem is null. Any ideas what am I missing?

Community
  • 1
  • 1
James
  • 75
  • 11
  • 1
    show your logic of implementation – Hakunamatata Jul 14 '15 at 21:24
  • Never mind, one of the methods was overriding cell values :/ – James Jul 15 '15 at 00:18
  • `((System.Web.UI.WebControls.Label)(GridView.Rows[i].FindControl("lblName"))).Text.ToString();` is working fine now, however `DataItem` is still null and `GridView.Rows[i].Cells[j].Text` is empty. weird. – James Jul 15 '15 at 00:27
  • Without looking your code hard to guess what could be the issue. Will be helpful if you can share the code snippet. However make sure that you are binding text box something like this Text='<%# Bind("ColumnName") %>' /> – DJay Jul 15 '15 at 01:28

1 Answers1

0

You can use Gridview Row DataBound event for this because you want to get the record just after gridview bind Like check this video

  • You should put relevant snippets from that article into your answer, in case the link goes dead. – ugo Jul 15 '15 at 03:08