OnClick method is not called

G

Guest

I want to select a row without using a button column, but instead just click
anywhere on the row. I also don't want to write a new control.

I am using the following code to create an onclick attribute to each cell
and I want to call my function onClickTableCell(), but when I click the
DataGrid, it does a postback, but doesn't call my function.

public void itemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
foreach( DataGridItem dgi in dgList.Items )
{
if ( dgi.ItemType != ListItemType.Header &&
dgi.ItemType != ListItemType.Footer &&
dgi.ItemType != ListItemType.Pager )
{
dgi.Attributes["onclick"] =
Page.GetPostBackClientHyperlink(dgi, "onClickTableCell");
}
}
}

public void onClickTableCell(object sender, EventArgs e)
{
// do the selection here.
string szClientId = dgList.ID;
}

Each row of my datagrid looks like the following:

<tr onclick="javascript:__doPostBack('dgList:_ctl2','onClickTableCell')"
style="background-color:#DEE1F5;">

what do I need to do to get my onClickTableCell method called?

Thanks,

Tim
 

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top