Get position index from data management

I want the javascript in the data row to bind to another control in the same row - show / hide, for example. The classic ASP approach was to type controls (usually using rowIndex to make them easier to reference. I wonder if there is a way to do this in ASP.Net without writing element command code?

So for html to display as follows

<div onClick='actOnX0'> <span id=x0>i am x0</span></div>
<div onClick='actOnX1'> <span id=x1>i am x1</span></div>
<div onClick='actOnX2'> <span id=x1>i am x2</span></div>

Can I insert numbers using the databound property, which returns, say, the rowIndex / item index of the current row?

+3
source share
2 answers

Try using the following code:

<%# Container.ItemIndex %>
<%# Container.DataSetIndex %>
+3
source

you can use

<%# Container.ItemIndex %>

,

rep.DataSource = new string[] { "", "", "" };
rep.ItemDataBound += (s, ev) =>
{
    // RepeaterItemEventArgs.Item.ItemIndex
    var i = ev.Item.ItemIndex;
};
rep.DataBind();
+6

Source: https://habr.com/ru/post/1767980/


All Articles