阳光博文 你的空间 知识的容器

.NET Repeater如何得到当前索引或主键?

 前台获取索引~


<asp:Repeater ID="Repeater1" runat="server">
 2             <ItemTemplate>
 3                 <div class="box1"><a href="<%#Eval("url") %>"><img src="<%#Eval("tupian") %>" /></a><p>姓名:<%#Eval("name"%>
 4                     <span style="color:#FF0000; margin-left:50px;"><%# Container.ItemIndex+1%></span>
 5                     <div>
 6                         <div class="piao">
 7                             <img src="images/toupiao.jpg" style="cursor: pointer;" onclick="UpDateNum('<%#Eval("id") %>','sp<%#Eval("id") %>');" />
 8                         </div>
 9                         <div class="wen">
10                             票数:<span id="sp<%#Eval("id") %>"><%#Eval("vote")%></span></div>
11                         <div class="clear">
12                         </div>
13                     </div>
14                     <%--<span style="color:#697f8c">评委点评:</span><%#Eval("ping"%>--%>
15                    </div></p>
16                  </div>
17             </ItemTemplate>

18 </asp:Repeater>

后台获取索引值~

1  protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)                    

 2    {
 3if(e.CommandName=="del")
 4       {
 5          my_conn.Open(); 
 6     string id = e.CommandArgument.ToString();//这里怎么得到Repeater当前索引? 

 7          string SqlAdd ="delete from bbs_reply where infoid="+ id +""
 8          OleDbCommand MyCmd =new OleDbCommand(SqlAdd, my_conn); 
 9          MyCmd.ExecuteNonQuery(); 
10          my_conn.Close(); 
11       }
12    }


在线咨询