在改写repeater控件中将一列数据采用链接方式,点击后查询相关列的详细信息,怎么实现?
发布网友
发布时间:2022-04-27 12:15
我来回答
共2个回答
热心网友
时间:2022-04-27 13:44
这个很简单呀
aspx文件:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<a href='default.aspx?ID=<%#Eval("EmployeeID") %>'><%#Eval("LastName") %></a><br />
</ItemTemplate>
</asp:Repeater>
——————————————————————————————
aspx.cs文件:
using System.Data.SqlClient;
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection("Server=.;database=northwind;uid=sa;pwd=123"))
{
SqlCommand comm = new SqlCommand("Select * from employees", conn);
SqlDataAdapter sda = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
sda.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
热心网友
时间:2022-04-27 15:02
<ItemTemplate>
<asp:HyperLink ID="hLink" runat="server" Text="查看" NavigateUrl='<%# "~/display.aspx?id="+Eval("id") %>' Target="_blank"></asp:HyperLink>
</ItemTemplate>
"~/display.aspx" 从根目录开始