views:

23

answers:

2

I want a javascript on a databound row to act on another control in the same row - show/hide for example. The classic ASP approach was to number the controls (usually by rowIndex so that they're easier to reference. I am wondering is there a way to do this in ASP.Net without writing any item command code?

So for html to render 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 the numbers using a databound property that returns say the rowIndex / item index of the current row?

+1  A: 

Try some code like below:

<%# Container.ItemIndex %>
<%# Container.DataSetIndex %>
Minh Nguyen
this is good to know thanks!
bizl
+2  A: 

You can use

<%# Container.ItemIndex %>

And if you are on the server-side you can use

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