关于Datalist超链接的问题
通过一个datalist实现超链接网页代码为:<asp:DataListID="DataList1"runat="server"Height="1px"Width="1p...
通过一个datalist实现超链接
网页代码为:
<asp:DataList ID="DataList1" runat="server" Height="1px"
Width="1px" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<table border="0" cellspacing="0" class="txt" style="width: 185px; height: 20px">
<tr>
<td colspan="3" style="height: 20px" align="center">
<asp:Image ID="Image1" runat="server" Height="35px" Width="120px" ImageUrl=<%#DataBinder.Eval(Container.DataItem,"picPath") %>/>
</td>
</tr>
<tr>
<td align="center" colspan="3" style="height: 20px">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="select" ForeColor="Black" Width="172px"><%# DataBinder.Eval(Container.DataItem,"linkName") %></asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" ForeColor="Blue" HorizontalAlign="Center" />
</asp:DataList>
我的后台代码为:
rLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
sqlcon = new SqlConnection(strCon);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from tbLink where id='" + id + "'", sqlcon);
da.Fill(ds, "tblink");
DataRow[] row = ds.Tables[0].Select();
foreach (DataRow rs in row)
{
strLink = rs["linkAddress"].ToString();
}
Response.Write("<script language=javascript>window.open('http://" + strLink + "')</script>");
bind();
}
//绑定
public void bind()
{
string sqlstr = "select top 4 * from tblink";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "tblink");
DataList1.DataSource = myds;
DataList1.DataKeyField = "ID";//主键
DataList1.DataBind();
sqlcon.Close();
}
} 展开
网页代码为:
<asp:DataList ID="DataList1" runat="server" Height="1px"
Width="1px" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<table border="0" cellspacing="0" class="txt" style="width: 185px; height: 20px">
<tr>
<td colspan="3" style="height: 20px" align="center">
<asp:Image ID="Image1" runat="server" Height="35px" Width="120px" ImageUrl=<%#DataBinder.Eval(Container.DataItem,"picPath") %>/>
</td>
</tr>
<tr>
<td align="center" colspan="3" style="height: 20px">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="select" ForeColor="Black" Width="172px"><%# DataBinder.Eval(Container.DataItem,"linkName") %></asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" ForeColor="Blue" HorizontalAlign="Center" />
</asp:DataList>
我的后台代码为:
rLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
sqlcon = new SqlConnection(strCon);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from tbLink where id='" + id + "'", sqlcon);
da.Fill(ds, "tblink");
DataRow[] row = ds.Tables[0].Select();
foreach (DataRow rs in row)
{
strLink = rs["linkAddress"].ToString();
}
Response.Write("<script language=javascript>window.open('http://" + strLink + "')</script>");
bind();
}
//绑定
public void bind()
{
string sqlstr = "select top 4 * from tblink";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "tblink");
DataList1.DataSource = myds;
DataList1.DataKeyField = "ID";//主键
DataList1.DataBind();
sqlcon.Close();
}
} 展开
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询