Datagrid cell values

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.
 
V

vMike

Maziar Aflatoun said:
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.
It depends on how your datatable is set up but here are some possibilities
which you can try. Obviously the cell number is based on your table.

e.item.cells(3).text (if your datacolumns are automatic)

Directcast(e.item.controls(3),tablecell).text (if your data is in an item
template)
DirectCast(e.Item.Cells(3).controls(0),textbox).text (if you data in in an
edit textbox, .net generates a textbox inside the cell in edit mode and the
control index always be 0)

You can also build a datakey with a separator add it to your column
collection and use something like this
split(DirectCast(sender,datagrid).datakeys(e.item.itemindex).tostring(),";x"
)


Hope this gives you something to go on.
Mike
 

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

Top