Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2009, 06:39 AM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Question Compare sql database field to name of the current page

Hi,
I want users of a website to be able to update text areas of their site using the site management pages.
I have set up a database table containing the PageName and the text areas they are able to edit.
I have created the means to update the table OK.

In the page where I want to display the data I have placed a Gridview control (might be better to use a Formview? - but I'll see) in the place where I want a section of text to appear.

I can configure the control so that it only displays the appropriate field (left column, right column) etc but I cannot figure out how to get an appropriate WHERE statement

What I want is:
SELECT PageName, LeftColumn FROM TextAreas WHERE Pagename = "the name of the current page".
Obviously, I need something that is available on every page.
I found this:
[code]
public string GetCurrentPageName()
{
string sPath = System.Web.HttpContext.Current.Request.Url.Absolut ePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}public string GetCurrentPageName()
[\code]
which I thought I could place in the CSS page but I get an errror that 'string' is not valid
And also I was not sure how I would then use it to create an effective WHERE....

Any thoughts anyone?
__________________
Geoff Baldwin
 
Old July 11th, 2009, 10:54 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I think you're making it more complicated than it needs to be. Just use an appropriate Request.Url object (I think there are shorter ones than AbsolutePath, but whatever works for you.) Store that in your database, and use it in your WHERE statement just like you're doing. I haven't tried doing it, but the only bumps I can see is that if you have slashes and punctuation you might need to escape them.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old July 12th, 2009, 07:39 AM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by chroniclemaster1 View Post
I think you're making it more complicated than it needs to be. Just use an appropriate Request.Url object (I think there are shorter ones than AbsolutePath, but whatever works for you.) Store that in your database, and use it in your WHERE statement just like you're doing. I haven't tried doing it, but the only bumps I can see is that if you have slashes and punctuation you might need to escape them.
Thanks for the response.
However, you assume a greater knowledge on my part than I actually possess :(
I am VERY MUCH a beginner learning 'on project'.

I have tried to look up the use of request.url. and it looks like I can use .segments??? to get the page name :

To test my theory I created a test page (aaTestingpage.aspx) with a label and put the following code in the code behind page:
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim WebPage As String = Request.Url.Segments.Clone / Page.ToString
        Label1.Text = WebPage
    End Sub
When I run the page I get the error:
Operator '/' is not defined for type 'String()' and string "ASP.aatestingpage_aspx".

If I use Request.Url.Segments.Clone.Page.ToString
I get:
Public member 'Page' on type 'String()' not found

Obviously, you can see that I am 'fishing' without solid knowledge.

Assuming I can get this syntax right with someone's help(!), Where would I put it so that the variable WebPage is available on every page and contains the name of the current page. In the code behind of the Masterpage? Or do I need to create a Base page and link all my pages to it?
And do I refer to it in my SELECT statement as WHERE PageName = '" & WebPage & "' or do I need to set something else up?

Appreciate the patience of all on the forum .
__________________
Geoff Baldwin





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Compare a TextBox Value to a SQL DataBase bex ASP.NET 2.0 Basics 1 January 27th, 2009 11:49 PM
Compare current value with previous parent node ratjetoes XSLT 2 July 17th, 2008 06:15 AM
Query a Sql Database Date Field feets Access VBA 3 October 18th, 2007 10:10 AM
string compare in table field alxtech SQL Server 2000 1 April 27th, 2007 12:25 AM
compare form field to database before submit chelle60 Javascript How-To 3 January 2nd, 2007 05:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.