当csdn排名升至2万却遇见难题:datalist指定行的超级链接
当csdn排名升至2万却遇见难题:datalist指定行的超级链接
a.aspx有两列:
CompanyName的值隐藏,用于传给b.aspx页面,
title只显示在a页面,不传给b页面,
按这逻辑,b.aspx应取到CompanyName 的值,实际取到的却是title的值
<asp:DataList id="DataList1" style="Z-INDEX: 101; LEFT: 0px; POSITION: absolute; TOP: 0px" runat="server" RepeatColumns="2" RepeatDirection="Horizontal" font-Size="12px" ItemStyle-Wrap="False" OnItemCommand="DataList1_ItemCommand" DataKeyField="ID" OnItemDataBound="DataList1_ItemDataBound">
<SelectedItemStyle ForeColor="Black"></SelectedItemStyle>
<SeparatorStyle ForeColor="#FF66FF"></SeparatorStyle>
<ItemStyle Wrap="False" HorizontalAlign="Justify" ForeColor="Black" Width="170px" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:LinkButton runat="server" id="link" Text='<%#show(DataBinder.Eval(Container.DataItem, "CompanyName"))%> '></asp:LinkButton>
<%#DataBinder.Eval(Container.DataItem, "title")%>
</ItemTemplate>
</asp:DataList>
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton LinkButton_CompanyName = (LinkButton)e.Item.FindControl("link");
LinkButton_CompanyName.Visible = false;
}
public string show(object CompanyName)
{
return "<a href=b.aspx?strCompanyName=" + CompanyName + " target='_blank'>" + CompanyName + " </a>";
}
------解决方案--------------------帮顶!!!
------解决方案--------------------把LinkButton改成HyperLink; 不用SHOW这个方法。
HTML code
<ItemTemplate>
<asp:HyperLink runat="server" id="link" Text='<%# Eval("CompanyName") %>' NavigateUrl='<%#"b.aspx?strCompanyName=" + Eval("CompanyName")%>' Target="_blank"> </asp:LinkButton>
<%#DataBinder.Eval(Container.DataItem, "title")%>
</ItemTemplate>