[英]how to add a onclick even on tables in ASP so that you can do something from the c# backend
i have this piece of code 我有这段代码
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>
Cell text
</asp:TableCell>
</asp:TableRow>
</asp:Table>
what i want to do is to make this table clicable and to process somthing at the back for example 我想要做的就是使这张桌子变得可笑,并在背面处理诸如此类的东西
void Table1_Click(Object sender, EventArgs e)
{
//do somthing
}
Can you not add an onclick event to the table? 您不能将onclick事件添加到表中吗? Like this.
像这样。 It has been a while since I did webforms.
自从我制作网络表单以来已经有一段时间了。
<asp:Table id="Table1" runat="server" OnClick="Table1_Click">
<asp:TableRow>
<asp:TableCell>
Cell text
</asp:TableCell>
</asp:TableRow>
</asp:Table>
Then use what you have for your backend. 然后将您的后端可用。
void Table1_Click(Object sender, EventArgs e)
{
//do somthing
}
You can wrap the entire Table with a LinkButton. 您可以使用LinkButton包装整个表。
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Button1_Click">
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>
Cell text
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:LinkButton>
I would suggest creating a JavaScript function and then making an Ajax call to a web method to call CS method. 我建议创建一个JavaScript函数,然后对Web方法进行Ajax调用以调用CS方法。
HTML: HTML:
<asp:Table ID="Table1" runat="server">
<asp:TableRow >
<asp:TableCell onclick="tablecell_click();">
hello
</asp:TableCell>
</asp:TableRow>
</asp:Table>
Javascript: Javascript:
function tablecell_click() {
//JQuery ajax call here
}
`in Jquery: 在Jquery中:
$(document).ready(function(){ $(document).ready(function(){
$("#Table1").on('click',function(){ $(“#Table1”)。on('click',function(){
alert(); 警报(); });
}); });`
});`
Create a button and use JQuery to click the button to do the PostBack. 创建一个按钮,然后使用JQuery单击该按钮以执行PostBack。 Call the JQuery using the onclick on the TableCell
使用TableCell的onclick调用JQuery
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell onclick="tablecell_click();">
hello
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button runat="server" id="btnCellClick" OnClick="Table1_Click"/>
<script>
function tablecell_click() {
$('#btnCellClick').click();
}
</script>
The asp:Repeater
control is what you need: 您需要的是
asp:Repeater
控件:
https://www.aspsnippets.com/Articles/Repeater-control-Tutorial-with-example-in-ASPNet-using-C-and-VBNet.aspx https://www.aspsnippets.com/Articles/Repeater-control-Tutorial-with-example-in-ASPNet-using-C-and-VBNet.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.