By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

datalist and selectedindex please helpppppppppppppppppppp

P: n/a
H
data I'm binding to the DataList is information about products in my product database. Perhaps passed in the QueryString to this page is a ProductID. I might want to make the item in the DataList that has the corresponding ProductID selected. In a similar vein, perhaps I want to have newest product selected by default. How can I acheieve this functionality
actuly i use pagin

<%@ Page language="c#" Codebehind="product.aspx.cs" AutoEventWireup="false" Inherits="nettest1.product" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><HEAD><title>product</title><meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta content="JavaScript" name="vs_defaultClientScript"><meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"><style>A.11pxblue { FONT-SIZE: 11px; COLOR: #00319b; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: underline
A.11pxblue:visited { FONT-SIZE: 11px; COLOR: #00319b; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: underline
A.11pxblue:hover { FONT-SIZE: 11px; COLOR: #00319b; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none
</style></HEAD><body MS_POSITIONING="GridLayout"><form id="Form1" method="post" runat="server"><table width="75%" border="0"><tr><td>&nbsp
<table><TBODY><tr><td></td></td><td><asp:datalist id="Dtl_ProInfo" runat="server" RepeatColumns="1" RepeatDirection="Horizontal"><SeparatorStyle BorderStyle="Solid" BorderColor="Control"></SeparatorStyle><ItemTemplate><table width="87%" border="0"><tr><td><table width="75%" border="0"><tr><td>imgdaralist</td></tr><tr><td>click here for larger view</td></tr><tr><td>pre next</td></tr></table></td><td><table width="75%" border="0"><tr><td>img</td></tr><tr><td>Click to enlarge image<br></td></tr></table></td><td><table width="100%" border="0"><tr><td><table width="100%" border="0"><tr><td>Our Price</td><td><%# DataBinder.Eval(Container.DataItem, "OurPricePerUnit1","{0:c}") %></td></tr><tr><td></td><td>&nbsp;</td></tr><tr><td>Retail Price:</td><td><%# DataBinder.Eval(Container.DataItem, "RetailPrice","{0:c}") %></td></tr><tr><td>You save:</td><td><%# DataBinder.Eval(Container.DataItem, "SavedValue","{0:c}") %>(<%# DataBinder.Eval(Container.DataItem, "SavedPercentage","{0:c}") %>%)</td></tr></table></td
Nam
</tr><tr><td><table width="75%" border="0"><tr><td>img</td><td><a>Order Sample o
<%# DataBinder.Eval(Container.DataItem, "Name","{0:c}") %
(<%# DataBinder.Eval(Container.DataItem, "PartNo","{0:c}") %>)</a></td></tr></table></td></tr><tr><td><table width="75%" border="0"><tr><td>Warranty Protectio
</td></tr><tr><td>More Informatio
</td></tr><tr><td>Reviews &amp; Ratin
</td></tr><tr><td>Add to Wish Lis
</td></tr></table><br></td></tr></table></td></tr></table></ItemTemplate></asp:datalist><asp:linkbutton id="Prev" onclick="Page_DataList" runat="server" Width="105px"><< pre</asp:linkbutton><asp:linkbutton id="Next" onclick="Page_DataList" runat="server" Width="78px">next >></asp:linkbutton><INPUT id="CurrentPage" type="hidden" value="1" runat="server" NAME="CurrentPage"><INPUT id="PageSize" type="hidden" value="1" runat="server" NAME="PageSize"><INPUT id="TotalSize" type="hidden" runat="server" NAME="TotalSize"></td></TD></tr></table></TD><tr><td>&nbsp;</td></tr><tr><td>&nbsp
<asp:datalist id="DataList3" runat="server"></asp:datalist></td></tr><tr><td>&nbsp
<asp:datalist id="DataList4" runat="server"></asp:datalist></td></tr><tr><td>&nbsp
<asp:datalist id="DataList5" runat="server"></asp:datalist></td></tr><tr><td>&nbsp;</td></tr></TBODY></TABLE></form></body></HTML

how can i show for example row(5) first in datalist

Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
This is how you can implement it. Here is an example of the
menucontrol.ascx.cs on IBuySpy Portal.for More Details
http://www.ibuyspy.com/IBS_Store/Sou...4RegardsAshish M
Bhonkiya<%@ Control Language="C#" %><%@ Import
Namespace="System.Data.SqlClient" %><%@ OutputCache Duration="3600"
VaryByParam="selection" %><script runat="server">
//************************************************** ***** // // The
Page_Load event on this page is used to obtain // from a database a list
of all product categories // and databind it to an asp:datalist control.
// // To optimize performance, this user control is output // cached
(varying based on the categoryId and selection // passed through the
querystring. //
//************************************************** ***** void
Page_Load(Object sender, EventArgs e) { // Set the curent
selection of list String selectionId = Request.Params["selection"];
if (selectionId != null) { MyList.SelectedIndex =
Int32.Parse(selectionId); } // Obtain list of menu categories
and databind to list control IBuySpy.ProductsDB products = new
IBuySpy.ProductsDB(); MyList.DataSource =
products.GetProductCategories();
List.DataBind(); }</script><table cellspacing="0" cellpadding="0"
width="145" border="0"> <tr valign="top"> <td colspan="2">
<a href="default.aspx"><img src="images/logo.gif" border="0"></a>
</td> </tr> <tr valign="top"> <td colspan="2">
<asp:DataList id="MyList" runat="server" cellpadding="3" cellspacing="0"
width="145" SelectedItemStyle-BackColor="dimgray" EnableViewState="false">
<ItemTemplate> <asp:HyperLink cssclass="MenuUnselected"
id="HyperLink1" Text='<%# DataBinder.Eval(Container.DataItem,
"CategoryName") %>' NavigateUrl='<%# "productslist.aspx?CategoryID=" +
DataBinder.Eval(Container.DataItem, "CategoryID") + "&selection=" +
Container.ItemIndex %>' runat="server" /> </ItemTemplate>
<SelectedItemTemplate> <asp:HyperLink
cssclass="MenuSelected" id="HyperLink2" Text='<%#
DataBinder.Eval(Container.DataItem, "CategoryName") %>' NavigateUrl='<%#
"productslist.aspx?CategoryID=" + DataBinder.Eval(Container.DataItem,
"CategoryID") + "&selection=" + Container.ItemIndex %>' runat="server" />
</SelectedItemTemplate> </asp:DataList> </td> </tr>
<tr> <td width="10"> </td> <td>
<br><br><br><br><br><br> <a href="docs/docs.htm" target="_blank"
class="SiteLink">IBuySpy Store<br>Documentation</a> </td>
</tr></table>
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.