Let's say we have following database table.
10101
Coffe ($3)
|
20992
Cheese Cake ($6)
|
28281
Tea ($2)
|
<asp:DataList ID="DataList1" runat="server" DataKeyField="fldProductID" DataSourceID="sqlProduct">
<ItemTemplate>
<P/>
<asp:Label ID="lblProductID" runat="server" Text='<%#Eval("fldProductID")%>'/>
<br />
<asp:Label ID="lblProductName" runat="server" Text='<%#Eval("fldProductName")%>'/>
(<asp:Label ID="lblProductPrice" runat="server" Text='<%#Eval("fldProductPrice")%>'/>)
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="sqlProduct" runat="server"
ConnectionString="<%$ ConnectionStrings:
YourDbConnectionString %>"
SelectCommand="
YourSelectCommand"/>
You want to make it so the user can click on product name and jump to the product
detail page.
On the product detail page (call it = pgePorductDetail.aspx), the data is filtered by the Query name BID. If you want to jump to product detail page for Tea, you need to create a link pgeProductDetail.aspx?BID=28281.
Let's make public function that returns such address when you feed product ID. (in
your code behind page)
Function strProductDetailPageByProductID(ByVal intProductID) As String
Return "pgeProductDetail.aspx?BID=" & intProductID
End Function
Now here is how you can call you function in your datalist.
<asp:Label ID="lblProductName" runat="server"
Text='<%# strProductDetailPageByProductID(DataBinder.Eval(Container.DataItem, "fldProductID"))%>'/>