通过Jquery获取转发器内的控件ID
我有一些条目我想对它们发表评论。所以我创建了一个带有文本框和 里面有按钮。如何获取特定行的按钮和文本框的 id jQuery?
<ASP:REPEATER runat="server">
<ItemTemplate>
...
// Entries: bind data from DB
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" />
</ItemTemplate>
</ASP:REPEATER>
谢谢 。
I have Entries I want to comment on them . So I created a Repeater with a TextBox and a
Button inside it . How can I get the id of the button and textbox for specific row by
Jquery ?
<ASP:REPEATER runat="server">
<ItemTemplate>
...
// Entries: bind data from DB
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" />
</ItemTemplate>
</ASP:REPEATER>
Thanks .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的大问题是你的asp转发器控件将生成像这样的id
ct100_repeater_txt1
这不会帮助你获得与其相应的数据库行关联的注释我发现完成此任务的常用方法(我认为这是一种非常标准的方法)是将元素 id 分配给数据库中的行 id,或者如果您无法控制 id,则创建自定义属性。
我使用的伪代码看起来像这样:(我将尝试使其与语言/平台无关,以便您可以学习概念,而不是仅学习语言)
应该生成如下所示的代码:
然后以您想要的任何语言你可以从这个属性中读到:
欢呼吧!希望这对你有用
编辑
回应评论“id 在哪里保存 dbid?!”我假设在数据库中:)如何保存它?有很多方法。您可以尝试使用 jquery:
创建一个 JavaScript 函数来保存带有参数的答案。当您将 dbid 绑定到控件时,将其绑定到 onclick 函数并将该 id 传递给该函数。然后,该函数获取 dbid 匹配的文本,并将评论和 id 保存到数据库中。
Your big problem is that your asp repeater control is going to generate ids like this
ct100_repeater_txt1
which isn't going to help you get that comment associated with its corresponding db rowThe common way I have found to accomplish this (which is a pretty standard way I believe) is to assign the elements id with the row id from the database, or if you have no control over the id, to create a custom attribute.
Pseudo code I have used looks something like this: (I'll try and make it language/platform agnostic so you can learn the concept, as opposed to only the language)
that should generate code that looks like:
Then in whatever language you want you can read from that attribute:
Many cheers! Hope that works for ya
EDIT
In response the the comment "where do id save the dbid?!" I'm assuming in a database :) How should you save it? There are lots of ways. Here's one you could try with jquery:
create a javascript function to save answers that takes a parameter. when you bind the dbid to the control, bind it into an onclick function and pass that id to the function. The function then gets the text where the dbid matches and saves the comment and id to a database.
没有更多信息,这是我可以为您提供的最好信息:
对于像这样的 html(这就是 ASP.NET 将如何呈现按钮/文本框):
您可以使用以下命令选择特定行的按钮和文本框 :以下 jQuery:
Without more information this is the best I can offer you:
for html like this (which is how asp.net will render your button/textbox):
You could select the
button and textbox for specific row
by using the following jQuery: