日期:2014-05-19  浏览次数:20482 次

DataList问题,一个按钮列,一个Label,分别绑定不同的列,点击按钮如何取得Label的值
以下是页面绑定的代码

<ItemTemplate>
<FONT   face= "宋体 "> &nbsp;
<asp:Image   id= "Image1 "   runat= "server "   ImageUrl= "images/SizePlus.gif "> </asp:Image> &nbsp;
<asp:LinkButton   id= "LinkButton1 "   runat= "server "   CommandName= "Select ">
<%#   (DataBinder.Eval(Container.DataItem,   "addtypename "))   %>
</asp:LinkButton>
<asp:Label   id= "Label2 "   runat= "server "   Width= "32px ">
<%#   (DataBinder.Eval(Container.DataItem,   "addtypeid "))   %>
</asp:Label> </FONT>
</ItemTemplate>
我在DataList1_ItemCommand()事件中
Label       tb       =       (Label)e.Item.FindControl( "Label2 ");  
string   tname=tb.Text
取出的值为空
各位看一下

------解决方案--------------------
你数据库绑定的代码呢?发出来看下
------解决方案--------------------
为空说明FindControl已经找到了,应该是其他地方的问题
------解决方案--------------------
FindControl
------解决方案--------------------
ding

------解决方案--------------------
就你发的这些代码不能说明你的目的啊,不是点击button才显示吗?是不是没初始化?或者要触法你的button事件才行?botton方法呢?
------解决方案--------------------
简单方法

<asp:datalist id= "zplist " runat= "server " RepeatColumns= "4 " RepeatDirection= "Horizontal " Width= "90% " >
<ItemTemplate> &nbsp;&nbsp;
<div style= "MARGIN-LEFT: 15px ">
<table border=0 bgcolor=WhiteSmoke>
<tr>
<td colspan=2 align=center valign=bottom height=150 bgcolor=White>
<a target=_blank href= "../lib/preview.aspx?Gid= <%=Gid%> &zid= <%# DataBinder.Eval(Container.DataItem, "id ")%> ">
<img id= 'image <%# DataBinder.Eval(Container.DataItem, "id ")%> ' onerror= "ChangeImg( 'image <%# DataBinder.Eval(Container.DataItem, "id ")%> ') " border=0 src= ' <%# DataBinder.Eval(Container.DataItem, "mapth ")%> '>
</a>
</td>
</tr>
<tr>
<td valign= "top "> 编号: </td>
<td valign= "top "> <%# DataBinder.Eval(Container.DataItem, "id ")%> </td>
</tr>
</table>
<asp:Label id= "tishi " Visible= "False " ForeColor= "#ff9900 " runat= "server "> </asp:Label>
</div>
</ItemTemplate>
</asp:datalist> </td>


Dim i As Integer
Dim nStep As Integer = 5
Dim nStart, nEnd As Integer
Dim db As New DataBase
Dim dt As DataTable
With db
.ClearCommandParameters()
.AddComandParameters( "@rid ", ridd.Text.Trim(), SqlDbType.Int, 4)
dt = .GetDataTable( "usp_quanlir_tupian ", CommandType.StoredProcedure)