不知道什么原因,在Datalist下面的LinkButton控件到后台就不能识别了?
<asp:DataList ID="dlFree" runat="server" RepeatColumns="1 "
onselectedindexchanged="dlFree_SelectedIndexChanged">
<ItemTemplate>
<table border="1px">
<tr>
<td>
<a href="javascript:window.location.href='showimage.aspx?id='+<%#DataBinder.Eval(Container.DataItem, "Mid ")%>">
<img style="border: 6px solid #ffffff; width: 200px; height: 200px;" alt="<%#DataBinder.Eval(Container.DataItem, "Title1 ")%>"
src='<%# DataBinder.Eval(Container.DataItem,"Photopath") %>' /></a>
</td>
<td>
<table style="width: 250px; font-size:12px;">
<tr>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" >收录</asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
不知道什么原因,在Datalist下面的LinkButton控件到后台就不能识别了.....
有解决方法吗?
------解决方案--------------------因为你这个linkbutton控件是在datalist里面的,必须要通过datalist事件来获取
C# code
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton link = (LinkButton)e.Item.FindControl( "link1 ");
//这里就获取到了link
}
------解决方案--------------------
也可以这样
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton link = e.Item.FindControl( "link1 ") as LinkButton;
}
------解决方案--------------------
------解决方案--------------------
加个判断可能好点
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item)
{
LinkButton link = e.Item.FindControl( "link1 ") as LinkButton;
}
}
}
------解决方案--------------------
<asp:LinkButton ID="LinkButton1" CommandName="sl" CommandArgument='传入阐述' runat="server" >收录</asp:LinkButton>
protected void DataList1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "sl")
{
//执行点击事件
Response.Write(e.CommandArgument);//输出传入的参数
}
}
------解决方案--------------------
HTML code
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("ID") %>' onclick="LinkButton1_Click">LinkButton</asp:LinkButton>