开发者

C# adding click event to TableCell in codebehind

开发者 https://www.devze.com 2023-02-22 03:42 出处:网络
I\'m trying to use the codebehind to add a click event to a TableCell..I basically want the user to be able to click a cell and cause a server side click event so that I can call a method with the GUI

I'm trying to use the codebehind to add a click event to a TableCell..I basically want the user to be able to click a cell and cause a server side click event so that I can call a method with the GUID of the item in the cell...seems this functionality should already be built-in but I've been unable to find much in the way of instru开发者_StackOverflow中文版ction. What am I missing?


You can add an attribute to the cell from code-behind.

First make sure the cell is marked runat="Server" in markup

Then in code behind add attributes such as

YOURCELLNAME.Attributes.Add("onmouseout", "this.style.cursor='pointer';this.style.backgroundImage='';");

or

YOURCELLNAME.Attributes.Add("onclick","NameOfAJavascriptFunctionHere");


Unfortunately this is not supported in ASP.Net. As a work arround, I would suggest adding a LinkButton without text and try to extend it to all the cell with Absolute value for Position.

Then use the button's click event.

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消