How To Display Results From A Url
Feb 3, 2011In my asp.net project I need to call another url with a parameter and display what the url returns in a label. What is the easiest way to do this?
View 2 RepliesIn my asp.net project I need to call another url with a parameter and display what the url returns in a label. What is the easiest way to do this?
View 2 RepliesFirstly, im a PHP developer trying to get my head around asp.net.
so i have created a basic MVC project.
I have a query without the fields known (ie. select * from products) how do I:
execute in Controller - my attempt:
public ActionResult getProducts()
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["myDB"].ToString()))
{
string sql = "select * from products";
SqlCommand cmd = new SqlCommand(sql, cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
return View();
}
how do i pass the results to a View and then loop through them like:
foreach ($data as $key => $val)
{
echo $key.' = '.$val.'<br>';
}
this is SOOOOO simple in PHP but seems to be very confusing in asp.net.
I have a common problem in an ASP.NET web form. I'm just surprised that I haven't found a common solution :)
I have a list of results being returned from a SQL Server database. I want to show those results in my web page with number to the left of them. For instance, my result set may look like the following:
New York | NY
Chicago | IL
Los Angeles | CA
In my web page, I would like to show them as:
1. New York, NY
2. Chicago, IL
3. Los Angeles, CA
I was surprised that I can't find a way to make the numbers automatically appear. Am i doing something wrong? If not, what is the recommended approach?
I want to display sql query results in my web application (asp.net webpage) dynamically at the run time. But I don't know how to do that. Is there any control to do that? Or is there any code? Could you give some examples?
View 4 RepliesI have this code:
Dim Result As New DataTable
DataAdapter.Fill(Result)
'bind data to visible surname/name grid
If Result.Rows.Count = 0 Then
NoInputBottom.Text = "No Results. Please widen your search criteria and try again"
NoInputTop.Text = "No Results. Please widen your search criteria and try again"
Else
GV.DataSource = Result
GV.DataBind()
End If
I have also tried moving the check to the gridview like so:
If GV.Columns.Count = 0 Then
NoInputBottom.Text = "No Options Selected: Please select your search criteria and try again" NoInputTop.Text = "No Options Selected: Please select your search criteria and try again" End If
When I run the code. the noinput labels do not have value, the null check seems to be failing? how to display a message if the search returned no reults.
I am trying to build a SharePoint 2007 web part in Visual Studio. This web part should search a sharepoint list and display the results.
What I want to accomplish is to display the results as soon as the user stops typing, so no clicking button involved.
Probably, a combination of text_changed event and onkeydown javascript?
This sharepoint site is "Ajax-enabled", btw.
I have objectDataSource connected to report viewer.
This datasource have a select method to filter the results by Dep_id parameter
Now if i want to include all results(All Departments) what should i do ???
I would like to query a DB and output the results to the webpage. What is the best way to do this while avoiding gridview, etc?
So far I have the following code: (which works)
sqlLookup = "SELECT * FROM locations";
string connectionString = WebConfigurationManager.ConnectionStrings["LocationDatabaseConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
SqlCommand myCommand = new SqlCommand(sqlLookup, myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
locationCode = myReader["locationCode"].ToString();
locationName = myReader["locationName"].ToString();
notes = myReader["notes"].ToString();
}
In the past I used to inject HTML into a DIV element via the WHILE loop but this always creates a huge delay when renering the page. Is there a better method?
I am developing a web form for search capability. The search query should return records from three different tables. How to display these three table records in three different rows. The search query should get the results from Table 1 and Table 2. Table 2 and Table 3 has a parent child relation ship. Which controls can I use for this purpose?
View 5 RepliesI have a simple .net form with two input boxes to choose the event and location. On button click, an xml url is built and this xml file is read using ReadXml, dataset is built and the results are displayed in the same page. I have both the forms to run at server and it says I cannot have it.
View 1 RepliesI'm developing a search page that will display the results in a gridview. The codebehind (in VB.NET) uses a SQL command to fill the gridview.
The gridview does have paging and sorting enabled. Once the search button is clicked the initial results are displayed, if the user clicks on a sorted column or wants to advance a page the gridview disappears. Enable Sorting And Paging Callbacks is set to True. Enable ViewState is also set to True.
My ComboBox is now rendering its button and results list on top of the ModalPopup panel
[URL] However, the results are showing up completely separate from the textbox. This is bacially the same problem described at [URL] However, forcing the position of the list did nothing and I'm already using the very latest (release) build of the toolkit (so alaa9jo's post about it being fixed in the November 2009 build isn't true for my instance).
I need the combobox functionality for my form.
why the scrollbars in comboboxes choose to show sometimes and not other? My main combobox is missing them, but the combobox reference above has them. Both use the same CSS settings and databindings; the only difference is that the one with scrollbars is inside the ModalPopup.
I would like to retrive data on database and display the results assyncronously
I think of using 2 threads : one thread reads data database and another thread displays the data that arrives.
i have an html editor where a user can put in some text.the thing is that when trying to display this text on a different page results in displaying the html that was saved by the editor.i want to display the text in a text box (if possible), with the special attributes(bold, itali etc.i currently get the text with the html tags.
View 5 RepliesI am using visual studio 2010, asp.net 4.0 (c#)
My problem is:
How do I display results from my database on a gridview based on the selected row of another gridview.
For example, I have a e-shop web app and I have a product categories table in my database displaying the data on a gridview.
I want to be able to click on the select button on each row and use that event to populate another gridview based on the ID of the product category that is clicked. E.g say the 'CDs' row is clicked, another gridview shows all the different CDs.
As a result, I need the select(sql) statement for the second table to be dynamic based on what the user clicks.
Has anyone done anything like this before?
I have a IEnumerable result, passed to my view. Now, I want to display five elements for my Model in one row and next five in second row. How can I do that?
View 1 RepliesI am displaying some query results in a div (table format). Is it possible to do pagination in vb.net in a div . Because i am not using any list view or data repeater or data grid control.
BID StartDate EndDate BidAmount Status
1 10/12/2010 14/12/2010 100000 Approved
2 05/07/2010 07/07/2010 500000 Pending for DAC
I want to display only 10 records per page.
I am trying to develop a page where I am trying to search a database (MyQSL) and display the data in a table format. Some of the database entries, like category, is stored as integer values, but I want to display the category name in the search result (not the corresponding integer value). I have also another issue, every time I change the dropdown list values (which are having "auto postback" enabled) the <EmptyDataTemplate> is returned. At this moment I am using GridView. But I am ready to change this to any other method, like repeater or whatever...
View 2 RepliesI have DataPager and ListView in one page aspx. DataPager is working if I do not search item. DataPager is not working to display the searching reasults. Below is the complete code in one page aspx. I am using VS 2008.
[Code]....
I want to search record based on Name, ID, Date, Report Type. from same table with one textbox. I can do search with one column how can do it with multiple column ...
protected void Button2_Click(object sender, EventArgs e)
{
DateTime dt = Convert.ToDateTime(TextBox1.Text);
SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions where report_type = @report_type ");
cmd.Connection = con;
[Code] .....
i want if i search UserName 'xdeeeee' that is not exist in database then a label should display saying "Sorry ‘USER NAME’ not found".
have a look below picture.
<asp:TextBox ID="SearchByUserName" runat="server"></asp:TextBox>
<asp:Button ID="SearchByTagButton" runat="server" Text="SEARCH" OnClick="SearchByTagButton_Click" /><br />
[Code].....
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 have a .Net 4 Chart Control bound to stored proc. For some customer selected queries the chart will be empty. I would like to display a "No data" message in the empty charting area so customers understand why the chart is empty. I haven't been able to find any information about how to do this.
View 1 RepliesNot sure if this is for SQL or .net! I have 3 tables which looks like
table1
ID Name
1 Jon
and
table2
ID Number Job
1 1 IT
2 1 Web
3 1 Admin
table1
ID ContractType
1 Temp
1 Perm
An inner join makes one table with 3 rows (I excluding the ID from table 2 for the join) which is saved as a view
viewTable
ID Name Number Job ContractType
1 Jon 1 IT Temp
2 Jon 1 Web Temp
3 Jon 1 Admin Temp
4 Jon 1 IT Perm
5 Jon 1 Web Perm
6 Jon 1 Admin Perm
I want to display these results on a web page via the grid view. However, I don't want to show the user 6 times! I want to show the user name once, the contract type once and each Job! What is the best way to do this? Is there a fault with the database design already? I assume the easiest answer is to not join them in a view but query each section 3 times from the website but I'd rather 1 connection only!
I need a query to fetch records from data from database based on partial text entered in textbox like search data from College table based on College Name entered in text box. I want that all record containing that College name displayed in grid view.
View 1 Replies