Forms Data Controls :: DataList No Results / Access Datasource On The Page With A Datalist To Show The Data?
Nov 15, 2010
The problem is that i have a search page. Access Database holding the information. I have a Access Datasource on the page with a Datalist to show the data. I need to find a way on setting it up to says "Sorry no results found" when the is no results. i am unsure on how to do this though.
I have a datalist and want the results paged I have written a pager.ascx page and have an aspx and aspx.cs page to display the results. I have a stored procedure to pull the data out of the database and a class to talk between the stored procedure and presentation controls I have the pager being displayed when the results get over the limit I have set to 10 in the web.config file but when i click on the next link to display the next page of results it doesn't do anything. my aspx page is
<uc1:Pager ID="topPager" runat="server" Visible="False" /> <asp:DataList ID="newsList" runat="server" CssClass="List" align="center"> <ItemStyle CssClass="ItemList" /> <ItemTemplate> <h2><%# Eval("Title") %></h2> <p>Posted <%# Eval("Date") %></p> <p><%# Eval("News").ToString().Replace(" ", "<br />") %></p> </ItemTemplate> </asp:DataList> <uc1:Pager ID="bottomPager" runat="server" Visible="False" /> my aspx.cs page is protected void Page_Load(object sender, EventArgs e) { // Retreive page from the query string string page = Request.QueryString["Page"]; if (page == null) page = "1"; // How many pages of posts int howManyPages = 1; // pager links format string firstPageUrl = ""; string pagerFormat = ""; //DataAccess.GetNews returns a DataTable object containing news data which is read into datalist newsList.DataSource = DataAccess.GetNews(page, out howManyPages); // Bind the data to the data source newsList.DataBind(); // have the current page as interger int currentPage = Int32.Parse(page); // Display pager controls topPager.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, false); bottomPager.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true); } my pager.ascx page is <p> Page <asp:Label ID="currentPagelabel" runat="server" /> of <asp:Label ID="howManyPageLabel" runat="server" /> | <asp:HyperLink ID="previousLink" runat="server">Previous</asp:HyperLink> <asp:Repeater ID="pagesRepeater" runat="server"> <ItemTemplate> <asp:HyperLink ID="hyperlink" runat="server" Text='<%# Eval("Page") %>' NavigateUrl='<%# Eval("Url") %>' /> </ItemTemplate> </asp:Repeater> <asp:HyperLink ID="nextLink" runat="server">Next</asp:HyperLink> </p> my pager.aspx.cs page is using System; // Simple struct that represents a (page number, url) association public struct PageUrl { private string page; private string url; // Page property definition public string Page { get { return page; } } // Url property definition public string Url { get { return url; } } // Constructor public PageUrl(string page, string url) { this.page = page; this.url = url; } } // The pager control public partial class UserControls_Pager : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } // Show the pager public void Show(int currentPage, int howManyPages, string firstPageUrl, string pageUrlFormat, bool showPages) { // Display paging controls if (howManyPages > 1) { // make the pager visable this.Visible = true; // Display the current page currentPagelabel.Text = currentPage.ToString(); howManyPageLabel.Text = howManyPages.ToString(); // Create the Previous link if (currentPage == 1) { previousLink.Enabled = false; } else { previousLink.NavigateUrl = (currentPage == 2) ? firstPageUrl : String.Format(pageUrlFormat, currentPage - 1); } // Create the Next link if (currentPage == howManyPages) { nextLink.Enabled = false; } else { nextLink.NavigateUrl = String.Format(pageUrlFormat, currentPage + 1); } // Create the page links if (showPages) { // The list of pages and their URLs as an array PageUrl[] pages = new PageUrl[howManyPages]; // Generate (page, url) elements pages[0] = new PageUrl("1", firstPageUrl); for (int i = 2; i <= howManyPages; i++) { pages[i - 1] = new PageUrl(i.ToString(), String.Format(pageUrlFormat, i)); } // Do not generate a link for current page pages[currentPage - 1] = new PageUrl((currentPage).ToString(), ""); // Feed the pages to the repeater pagesRepeater.DataSource = pages; pagesRepeater.DataBind(); } } } } my class file is // Retreive the list of news posts public static DataTable GetNews(string pageNumber, out int howManyPages) { // Get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // Set the stored procedure name comm.CommandText = "GetNews"; // create a new parameter for page number DbParameter param = comm.CreateParameter(); param.ParameterName = "@PageNumber"; param.Value = pageNumber; param.DbType = DbType.Int32; comm.Parameters.Add(param); // create a new parameter for products per page param = comm.CreateParameter(); param.ParameterName = "@PostsPerPage"; param.Value = PlatiumMindProductionsConfiguration.PostsPerPage; param.DbType = DbType.Int32; comm.Parameters.Add(param); param = comm.CreateParameter(); param.ParameterName = "@HowManyPosts"; param.Direction = ParameterDirection.Output; param.DbType = DbType.Int32; comm.Parameters.Add(param); // Execute the stored procedure and saven the results in a DataTable DataTable table = GenericDataAccess.ExecuteSelectCommand(comm); // Calculate how many pages of posts and set the out parameter int howManyPosts = Int32.Parse(comm.Parameters["@HowManyPosts"].Value.ToString()); howManyPages = (int)Math.Ceiling((double)howManyPosts / (double)PlatiumMindProductionsConfiguration.PostsPerPage); // return the page of posts return table; } my stored procedure is ALTER PROCEDURE [dbo].[GetNews] (@PageNumber INT, @PostsPerPage INT, @HowManyPosts INT OUTPUT) AS -- Declare a new table DECLARE @News TABLE (RowNumber INT, NewsID INT, Title NVARCHAR(50), Date DATETIME, News NVARCHAR(MAX)) -- Populate the table with the complete list INSERT INTO @News SELECT ROW_NUMBER() OVER (ORDER BY NewsID desc), NewsID, Title, Date, News FROM News -- return the total number of posts SELECT @HowManyPosts = COUNT(NewsID) FROM News -- extract the request page of posts SELECT NewsID, Title, DATE, News FROM @News WHERE RowNumber > (@PageNumber - 1) * @PostsPerPage AND RowNumber <= @PageNumber * @PostsPerPage
I read a few VB books and ready or not, I going to start building!I am "very afraid" of code behind. Frankly, much of what I read about OOP went a bit over my head and am hoping by "doing" it will all come together. That said...
Datalist results. I want them to hyperlink to another page with a querystring. I moved a hyperlink control into the EDIT TEMPLATE box and removed the origianal label that was in the box. I did some editing and was able to come up with a hyperlink, but I really need a hyperlink to a new page with the original result of the datalist being the querystring parameter. For example...
If BABE RUTH is the datalist result, I want the querystring to be www.mysite.com?athlete=BABE%20RUTH. I am fairly competant in asp classic. I feel like a guy who has amnesia and has to learn the most basic stuff from scratch.
Am building a Form for out intranet that runs on ASP.NET and C#, it is to be a survey from a SQL database. I have the connections setup can pull informations/Questions from the database. I am having a problem with setting up radio buttons within a datalist, ive never done this and i know they require unque names.
It is to be 4 radio buttons per question where only one can be select, i know how to group just not via a datalist with unique names
I am trying to place a datalist inside datalist. I managed to place a datalist inside gridview but not datalist inside datalist.
Below is the code I am using to bind the datalist into the master gridview, I am trying to change this code in such way it will be right for datalist inside datalist but so far I did not succeed.
i have a datalist . that is contains 7 columns in repeat layout .when i have more from 7 columns , datalist style is normal .but when i have smaller than 7 columns ! data list style is not normal,
because there are some empty columns without specific schema.
How i can make a datalist > when i have 1 columns in my datalist my first layout width be 100% ;
I want to show just the first row or the datalist although datareader returns x number of rows. I need to use it for printing so is it possible to get x number of wors from the datareader and display just the first row hiding all other (it will make printingeasier)
have a problem...i have to show a calendar using datalists.....the format is like this:- http://sualumni.org/event_calendar.aspi have to show upcoming events datewise...but that is seperate issue...but the point here is...how to program a datalist to show this form of calendar according to day name(sun, mon...etc.), month, number of days in a month
I want to load data from database and show randomly in datalist.. like when user see the page all the data from database showing on the page using datalist or listview.
and when the user refresh the page, all the data randomly changed and show in the datalist or listveiw..
I have One site in which i have to show products using datalist and use of paging is must i have created the same but its not very effective i want the paging same as [URL]
I can't seem to access a label that is outside the DataList. I wish to add the data in the label into a database, aswell as data that is inside the datalist (this is already working though). My SQL-query with only the specific label looks like this at the moment:
[Code]....
The data is added to the database when pressing a button inside the datalist (using onItemCommand). If I write UserIDLabel.Text the regular way it doesn't work either. The label is in the MasterPage, while the datalist is in a .aspx-page. If it is possible to somehow access the data that is in this label and add it to the database I would be ever grateful. Or is it somehow possible to add data that is in a Session and add it to the database?
There is two checkbox group which have same datasource, so in both case same checkbox are showing and also same event is firing for both. Here is the event code
Now what i want to do is, while check one checkbox from the 1st checkbox group the same checkbox should be selected from the second checkbox group automatically, also if i deselect one checkbox that should be deselect from both checkbox group.
I have a DataList called Books on my form. If the Genre is Mystery, I want the TableHeaderCell to be a different color. The BackColor is set by default to: #66CCFF.
How do I access this control in the code behind? I want to be able to say:
I try to make button inside datalist to be invisble based on a column value from database. I am able to read the column data but i cant find solution to make the button invisible. Below is my code behind:-
i am developing an ASP.NET website, i have a datalist that contains an item template with hyperlink in it, i want to access the hyperlink clicked i tried "SelectedIndexChanged" event, i don't know what to do. here is the code <asp:DataList ID="DataList1" runat="server" DataKeyField="album_id"
I am writing a system that is input intensive, and the used need to be able to use without touching the mouse. I am trapping the enter key and defaulting to click an "Enter" button that I have on the screen. In the EnterButton_Click event, I am using a "menu option" to determine which DataList item they want.
All of that is working great, except reading back the URL from the DataList Item, which I need for my repsonse.redirect to call the next screen.
[Code]....
I am inches away from pulling this off.Entire code is below. The actual datatable/datasource will come from a file later, I just mocked up some links for this example.