Monday, February 27, 2012

how can i get to rows five to ten in my table?

I need to pull out rows five to ten with my sqlDataSource. is this possible?

If you are using SQL Server (Express) 2005, you can use theRow_Number function

|||

How do i use this. is it easy? CAN I WRITE sql DIRECT TO THE SQLDATASOURCE?

|||

Here is a sample:

<asp:SqlDataSourceID="SqlDataSource1"Runat="server"SelectCommand="SELECT ProductID, ProductName, CategoryID FROM (SELECT ProductID, ProductName, CategoryID, ROW_NUMBER() OVER(ORDER BY [ProductID] ASC) as rowNum FROM Products) t WHERE rowNum>4 and RowNum<=10"ConnectionString="<%$ ConnectionStrings:NWConnectionString %>">

</asp:SqlDataSource>

<asp:GridViewID="GridView1"runat="server"DataSourceID="SqlDataSource1"AutoGenerateColumns="False"DataKeyNames="ProductID">

<Columns>

<asp:BoundFieldDataField="ProductID"HeaderText="ProductID"InsertVisible="False"

ReadOnly="True"SortExpression="ProductID"/>

<asp:BoundFieldDataField="ProductName"HeaderText="ProductName"SortExpression="ProductName"/>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"SortExpression="CategoryID"/>

</Columns>

</asp:GridView>

|||

Thanks. That worked!!

No comments:

Post a Comment