AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Question Sorted - DataList / PageDataSource (5 BELOW ) answered here.
Posted by Charlie Childs on  4/23/2010 7:22:45 AM Category: ADO.NET
Add to my favorites
Email to friend
Re: Moderator 1's lesson - Paging a Datalist using PagedDataSource.
I needed to know how to return paged results of categories selected from a dropdownlist.
Have achieved that with the below.

private void BindGrid()
{
SqlConnection conn = new SqlConnection("Data Source=tcp:s02.winhost.com;Initial Catalog=DB_5890_maindb1;User ID=DB_5890_maindb1_user;Password=bootsie23000;Integrated Security=False;");
SqlCommand cmd = new SqlCommand("SELECT [ProductCode], [ImgUrl], [Featuring], [Title] FROM [TableSG1] WHERE [ProdCategoryID] = @ProdCategoryID ORDER BY [Featuring]", conn);

SqlParameter param = new SqlParameter();
param.ParameterName = "@ProdCategoryID";
param.Value = DropDownList1.SelectedItem.Value;
cmd.Parameters.Add(param);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue);
pds.CurrentPageIndex = CurrentPage;
lnkbtnNext.Enabled = !pds.IsLastPage;
lnkbtnPrevious.Enabled = !pds.IsFirstPage;

DataList1.DataSource = pds;
DataList1.DataBind();

doPaging();
}

Then hooked the DropDownList1 SelectecIndexChanged event to ddlPageSize SelectecIndexChanged


Post Your Reply Post New Question

 Viewer's Reply
Answer for DataList and PageDataSource
Answered By Moderator1 on 4/23/2010 10:26:59 AM
Hi,

Its very good to see you taking initiative to post the solutions you got for the problem you got. But I would always recommend you to keep a single post for the same issues. Then you, me and the followers of this same problem can find the solution easily in a single post.. Kindly follow this in future.

Hi all, related post found at
http://www.aspdotnetcodes.com/ViewQuestion_429.aspx
http://www.aspdotnetcodes.com/ViewQuestion_442.aspx
http://www.aspdotnetcodes.com/ViewQuestion_449.aspx
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Backup and Recovery Best Practices for Microsoft SQL Server 2005
Everything You Know About CSS Is Wrong! - Free 37 Page Preview!
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)