Datagrid - reading the cell content

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
M

Maziar Aflatoun

Hi,

I have a datagrid which binds to a datareader

dgXXXXX.DataSource = rdr;
dgXXXXX.DataBind();

On dgXXXXX_EditCommand I can read the value of the selected row(
e.Item.ItemIndex) which works. How can I read the contents of that cell. I
have the following code which doesn't work.


dgXXXXX.EditItemIndex = e.Item.ItemIndex;

Filename = dgXXXXX.Items[e.Item.ItemIndex].Cells[2].Text;

Response.Write("Filename:" + Filename);

Can't I grab a cell content of a datagrid?


Thank you
Maziar A.
 
Once you've identified the cell you want, you need to identify the control
that is in that cell that holds the data. The cell most likely contains a
label and it is the label that contains the text. Try:

e.Item.ItemIndex.Cells[2].FindControl[controlName].Text
 
Maziar:
It might be easier if you put the value in a hidden form field <input
type="hidden" id="filename" runat="Server" value='<%#
DataBinder.Eval(Container.DataItem, "filename")%>' /> and use
e.Item.FindControl("filename") to get a reference to field in onEditCommand.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top