如何为项目模板中的每一行设置一个唯一的ID,并将其标签链接到该ID [英] How to set an id that it would be unique for each row in an items template and have its label link to that id
问题描述
hey there, here is my code and i'll explain my issue below it.
<pre lang="HTML"> <ItemTemplate>...<input class="hideelement toggle" id="<%#Eval("ID") %>" type="checkbox" checked="checked"><label class="lblscanImg" for="<%#Eval("ID") %> "> view scan</label>... </ItemTemplate>
我想将标签链接到输入。问题是'label'的id对于所有行都是一样的。?!当我在网格视图中选择任何标签时,只会影响第一行中的第一个元素。我检查了代码,所有标签都有相同的ID。我正在尝试使id唯一,这样当我在网格中选择任何随机标签时,只有在所选标签行内,其元素才会发生变化。
也没有回发帖子。总而言之:我可以用什么方式更改id,它对所有行都是唯一的。
我希望你明白。感谢帮助。
我尝试过:
i尝试过为了使选择静态,我试过但java脚本作为id,我不知道该怎么做。
I would like to link the label to input. the problem is the 'label's' id is the same for all the rows.?! when i select any label in the grid view, only the first element in the first row is affected. i inspected code behind and all the labels have the same id. I'm trying to make the id's unique so that when i select any random label in the grid, only within the selected labels row would its element change.
there is also no post back. so in conclusion: in what way can i change the id, that it would be unique for all rows.
I hope you understand. appreciate the help.
What I have tried:
i have tried to make the selection static, i have tried to but java script as the id, i no idea what to do.
推荐答案
你可以使用ItemIndex获得一个唯一的每行数量
You can use the ItemIndex to get a unique number per row
<input id="<%#Container.ItemIndex.ToString() %>" ...
这篇关于如何为项目模板中的每一行设置一个唯一的ID,并将其标签链接到该ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!