How to map DataNavigateUrlFormatString of Gridview Hyperlink Field dynamicatlly vb.net? - asp.net

Hope you are having a nice day.
I am developing a gridview for a list of songs with a hyperlink field like below. I left unnecessary codes by the way. The purpose of hyperlink field is for user to download songs. I am using visual studio 2010 and I am still using development server such as http://Localhost:xxxx/mypage.aspx. So I have to update the hyperlink field everytime I run this page in order to keep the link correct. I understand once i put on the live server, i just need to put the domain and this problem is fixed but I am wondering if there is a way to dynamically map the path of DataNavigateUrlFormatString to the development server URL so that I don't need to keep changing while I am on development server.
Thanks a lot.
<asp:GridView>
<Columns>
<asp:BoundField DataField="Song_Name" HeaderText="Song_Name" SortExpression="Song_Name" />
<asp:HyperLinkField DataNavigateUrlFields="Song_Location"
DataNavigateUrlFormatString="http://localhost:6686/RioMusic/Uploads/{0}"
DataTextField="Song_Name" HeaderText="Download" />
</Columns>
</asp:GridView>

Can you just use a relative link? I.e.:
Uploads/{0}
(This will be relative to the page displaying the link.)
Or, if you wish to specify a url relative from the root of your site:
~/RioMusic/Uploads/{0}

Related

Same piece of code works on one page & doesnt work on other Page, asp.net

nesting of image inside a LinkButton shows image on one page & doesn't show image on another page below are two sample code from two different pages in the same root director.It works fine on one page but on the other page is doesn't show any download image rather shows the text download in place of image.
I have done troubleshooting for sometime and replace the code also but it doesnt show download image for any reason on the second page..
<asp:LinkButton ID="lnkbtnDownload" runat="server" onclick="lnkbtnDownload_Click" meta:resourcekey="lnkbtnDownloadResource1">
<asp:Image ID="imgDownload" runat="server" ImageUrl="~/images/download.png" meta:resourcekey="imgDownloadResource1" />
</asp:LinkButton>
<asp:LinkButton ID="lnkbtnDownload" runat="server" onclick="lnkbtnDownload_Click" meta:resourcekey="lnkbtnDownloadResource1">
<asp:Image ID="imgDownload" runat="server" ImageUrl="~/images/download.png" meta:resourcekey="imgDownloadResource1" />
</asp:LinkButton>
HTML OUTPUT
HTML for above two code sample render as below
<img alt="Download" src="images/download.png" id="MainContent_imgDownload">
Download
Both Pages are in the same root directory...
The problem probably comes from a discrepancy in your resource files or missing a resource file completely for the second page. Obviously you have one for the first, but possibly not for the other which has different naming.
If you are using meta:resourcekey, there are some things you have to considerate.
Make sure that your local resource files meet the following criteria:
They are in an App_LocalResources folder.
The base name matches the page name.
For example, if you are working with the page named Default.aspx, the
resource files are named Default.aspx.resx (for the default
resources), Default.aspx.es.resx, Default.aspx.es-mx.resx, and so on.
The resources in the file use the naming convention
resourcekey."property". For example, key name Button1."Text".
Source: MSDN

turn sql rows into links on a vb.net page?

I am trying to create a specific aspx page where I display clickable links based on information in a sql database. For example one column could be the anchor tag another column could be the path to the link itself etc. In the past I would pull this information from sql and put it into a non-visible Label (say linkLabel1). Then in the page itself I would insert <%linkLabel1.text%> to insert the link path from the database to the appropriate area.
I hope I'm not confusing things too much here and that makes sense how I explained it.
What I would like to do is set up a way that I could simply enter a new row into a SQL table with link information and a web page automatically displays the new link for me.
I guess I am mostly looking for insight, opinions, or directions of what approach to consider. I can elaborate if I was unclear (wouldn't be awfully surprising if I was not).
Thanks in advance for anyone's time on this matter.
Since you are displaying this in a table, you could use a GridView for this. The columns that will display the link could be defined as hyperlink columns as so:
<Columns>
<asp:HyperLinkField
HeaderText="Header text"
DataNavigateUrlFields="PropertyContainingTheHRefForTheAnchor"
DataTextField="PropertyContainingTheTextForTheAnchor"
/>
</Columns>
So for example, if you return a record set containing these columns:
TextProperty PathProperty
See Details Assets/SomeOther/
Click me Products/AnotherPath/
Your grid will render these as:
See Details
Click me
If you define the column as:
<Columns>
<asp:HyperLinkField
HeaderText="Header text"
DataNavigateUrlFields="PathProperty"
DataTextField="TextProperty"
/>
</Columns>

How to specify path relative to current Master Page File

I am new to asp.net but Master Pages seem to do what I need - allow me to configure different templates/presentations/styles in runtime, so my app may take on a different look and feel by selecting a different Master Page. Each Master Page sits in its own folder with a set of images tailored for that "template" - I then want, in content pages, to reference various images sitting in the folder of the currently selected Master Page, for example the navigation buttons in a DataPager:
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"
PageSize="25">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image" ShowFirstPageButton="True"
ShowNextPageButton="False"
FirstPageImageUrl="<<Current Master Root>>/img/action-first.png"
PreviousPageImageUrl="<<Current Master Root>>/img/action-prev.png" />
<asp:NumericPagerField ButtonCount="10" NextPageText=">>"
PreviousPageText="<<" />
<asp:NextPreviousPagerField ButtonType="Image" ShowLastPageButton="True"
ShowPreviousPageButton="False"
LastPageImageUrl="<<Current Master Root>>/img/action-last.png"
NextPageImageUrl="<<Current Master Root>>/img/action-next.png" />
</Fields>
</asp:DataPager>
TEST: "<%= System.IO.Path.GetDirectoryName(MasterPageFile) %>"
(this does not work if we try to use it inside the DataPager?)
Is there a proper way to be doing this, like the tilda ~ character is used to get to the application root folder? Setting this in code is also proving to be tedious, especially for things like DataPager where the properties are nested in dynamic lists of sub controls (For example I do not know how to set the property DataPager1.Fields[0].NextPreviousPagerField.FirstPageImageUrl in code).
I have found trying to do this with Themes requires more coding than I started with because I have to include the entire control definition in the skin file, not just the image url properties, and then I have to duplicate that code in every single theme/skin. If I happen to want a DataPager with a different configuration of buttons and/or numeric fields then I have to duplicate those variations in every skin file also. If I make a change at a later date I will have to remember to make that change in all skins also - seriously defeating the purpose of separating the code from the skin.
My application runs multiple projects, and each project may select its own template. For the entire application I want to say: if the current project uses TemplateX then use images from folder /TemplateX/img/, if TemplateY is seletected then use images from /TemplateY/img/. As you know CSS cannot always be relied upon to determine what image to use where, so we have to be able to put the image reference directly in the HTML output.
In the custom ISAPI DLL web system I developed I simply use a substitution string like "[#HTML.Template]/img/prev.png" to stick the template folder in front of the image URL. Is there perhaps a way I can hook a custom .aspx preprocessor to manually substitute all ocurrences of, as in the example above, "<< Current Master Root >>" with the currently selected folder?
try use smething like this
var path = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;

displaying image in gridview column

I have image in the image folder and in my oracle database I have a column with the name IMG which has the name of
the image like ab.jpg
I have another column with name IMG1 which is storing the whole url like images/ab.jpg
I can see all the values of my database table in my dataset as well including IMG column and IMG1 column
In my aspx file I wrote code
but it is not displaying anything, however aspx page is working fine, it is showing a field but no image and it is blank, same is
the case with IMG1 column as well
Why is it so? What is wrong that I am doing?
I dont want to store image in database, so i store it in the folder
What method should i adopt to make it work?
Update
thats my code
<Columns>
<asp:BoundField DataField= "DD" HtmlEncode="false" HeaderStyle-BorderColor="green"
HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Arial"
HeaderStyle-Width="100%" HeaderStyle-Wrap="true" HeaderText="HEAD"
ItemStyle-Width="100%" >
<ItemStyle BorderColor="green" HorizontalAlign="Center" Wrap="true" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" ImageUrl="~/images/ab.jpg" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CC" HeaderText="SHEET" />
</Columns>
If I look at design section it is giving me image sign with a cross but not showing the actual image
location of image is
I have folder A and there I have sub folder images and mywebpage
so both mywebpage and images folder is in folder A
I have used paths as ~/images/ab.jpg and ~A/images/ab.jpg and in both cases it does not work
Method below does not work either
Using Oracle database, which is showing image url columns on dataset and even on grid as mentioned in my last post
What wrong am I doing?
Any solution?
You haven't share your code but you can use ImageField of GridView and set the DataImageUrlField to your image url.
You can alternatively go with TemplateField if you want more control over manipulation of url.
Sharing your code will have if the above doesn't meet your need.
Edit 1:
Since your page and images folder are in same folder try: ImageUrl="images/ab.jpg"
Although ImageUr"~/A/images/ab.jpg" should have worked.
Also to point sometimes the images might not appear in DesignView, so did you try opening your page in browser?

How to show Image with http url in asp.net

In sql server database, I have column name Image which has urls like http://www.xyz.com/1009/image1.jpg
Now I want to display it on my datalist. But it is not showing any image. It is might be the case because it is expecting the Image URL to be ~/Folder/abc.jpg
Then how to show the image on the asp.net page when I have image URL, which control I need to use and how?
Do you see little red X instead of an image?
If so, right click it --> Properties (IE) to see the URL it's referring to.
Might give us hint on what's going on. :)
If you are getting the image from the database in for the form xzy.com/1009/image1.jpg but want to add the http:// then your code should be
<asp:Image ID="imgmain" runat="server" ImageUrl='<%#String.Format("http://{0}", Eval("Image"))%>' Width="80" Height="80" />

Resources