日期:2014-05-17  浏览次数:20464 次

请教如何获得datalist的值
请教一个很菜的问题,因为最近刚转用C#写一段程序,很多地方不熟悉,

前台代码:

<asp:DataList ID="DataList1" runat="server" CellPadding="4" 
  ForeColor="#333333" Width="100%"
  RepeatColumns="3" RepeatDirection="Horizontal" 
  onselectedindexchanged="DataList1_SelectedIndexChanged">
  <FooterStyle BackColor="White" Font-Bold="True" ForeColor="White" />
  <AlternatingItemStyle BackColor="White" />
  <ItemStyle BackColor="White" ForeColor="#333333" />
  <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True"
  ForeColor="Navy" />
  <HeaderStyle BackColor="#990000" Font-Bold="True"
  ForeColor="White" />
  <ItemTemplate>
  <center><table><tr><td align="center" valign="baseline">
  <a href='Stationdetail.aspx?cinvcode=<%# Eval("cinvcode") %>'>
  <%-- <td> <asp:Label ID = "cinvcode " Text= <%# Eval("cinvcode") %> /> </td>--%>
  <img alt="" style="border-width:0px"
  src='../image/<%#Eval("smallphtofile") %>' /></a><br />
  <a href='Stationdetail.aspx?cinvcode=<%# Eval("cinvcode") %>'>
  <%# Eval("cinvname")%></a><br />
  资源租赁价格:<%#Eval("iInvsprice")%>
  <tr>
<td>&nbsp;</td>
<td><asp:Button ID="btnBuy" runat="server" Text="加入购物车" OnClick="btnBuy_onclick" CausesValidation="False" /></td>
</tr>
   
  </td></tr></table>
  </center>
   
  </ItemTemplate>
  </asp:DataList>

这里展示的是一个资源,里面加了一个按钮,“加入购物车”
现在想点击这个按钮获得站点资源的编号值cinvcode,然后加入到购物车,不知道应该怎样获得这个值?
之前看到的都是findcontrol,然后获得label值,
不知道是我前台代码绑定有问题还是怎的?如何获得这里的cinvcode值呢?

谢了,很急又很菜的问题。





------解决方案--------------------
你不是用了一个链接跳转了吗???
<a href='Stationdetail.aspx?cinvcode=<%# Eval("cinvcode") %>'>

在那个页面用Request.QueryString["cinvcode"]就能获取到
------解决方案--------------------
<a id="cinvcode" runat="server" href='Stationdetail.aspx?cinvcode=<%# Eval("cinvcode") %>'>

然后再用DataList1.Items[0].findcontrol("cinvcode")