473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OnClick method is not called

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','o nClickTableCell')"
style="background-color:#DEE1F5;">

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

Thanks,

Tim

May 10 '06 #1
1 1331
Perhaps this one helps
http://forums.asp.net/thread/982344.aspx

I've also blogged about how to create a row-clickable DataGrid or
GridView(it's not that hard to write a control for it)
http://aspadvice.com/blogs/joteke/ar...1/30/2315.aspx
http://aspadvice.com/blogs/joteke/ar.../07/14576.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Little Gazer" <Li*********@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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','o nClickTableCell')"
style="background-color:#DEE1F5;">

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

Thanks,

Tim

May 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: waste | last post by:
hello. is it possible to clear onClick event? eg: <div ... onClick="someFunction()"> when I want to run someFunction() only once. -- waste
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
4
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML...
53
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> ...
3
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it...
5
by: Fred.Grieco | last post by:
Hi every body, I have a little pb and I'm turning around : function MyFCTN(var1,var2) { var mytable = document.getElementById("myTBL"); for (var i=myTBL.childNodes.length-1; i>0; i--){...
3
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick...
7
by: yywangwang | last post by:
I followed the steps in http://www.thescripts.com/forum/thread147546.html and use it for a button. I have a button inside a form defined as this: <input name="save" type="button"...
4
by: mcelary | last post by:
When the user clicks a radio button it creates a postback where I add a button control dynamically. My problem is I cannot get the dynamically added button to work with on an click event. The button...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.