Clickevent in datacell

M

MA

Hi all!

I have a datagrid that i fill up from a database.

I create it with help of datatable and datarow. Then I creates a new
dataview and binds it to the datatable.

How do I get the clickevent on each cell with this?

I want to click on a cell in my grid, get the cellID or some else info that
can identify the cell. After that I want to go to a function in my code
behinde and launch a new window with extended information.

Can anyone tell me how to do this or give me a url with info?

/Marre
 
E

Eliyahu Goldin

In ItemDataBound event add Attributes["onclick"] to every cell of data
items. Pass cell id to the event handler javascript function.

Example:

private void myGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}

for (int i=0; i<e.Item.Cells.Count; i++)
e.Item.Cells.Attributes["onclick"]=String.Format
("'onclickHandler(this,{0})'", i);
}

Eliyahu
 
M

MA

Yeah! This works if I remove the ' around the functionname.

Thanx Eliyahu!!
/Marre

Eliyahu Goldin said:
In ItemDataBound event add Attributes["onclick"] to every cell of data
items. Pass cell id to the event handler javascript function.

Example:

private void myGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}

for (int i=0; i<e.Item.Cells.Count; i++)
e.Item.Cells.Attributes["onclick"]=String.Format
("'onclickHandler(this,{0})'", i);
}

Eliyahu

MA said:
Hi all!

I have a datagrid that i fill up from a database.

I create it with help of datatable and datarow. Then I creates a new
dataview and binds it to the datatable.

How do I get the clickevent on each cell with this?

I want to click on a cell in my grid, get the cellID or some else info that
can identify the cell. After that I want to go to a function in my code
behinde and launch a new window with extended information.

Can anyone tell me how to do this or give me a url with info?

/Marre
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top