By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

How to list out table items in aspx?

P: n/a
Tom
Hi,

I created a table with a field to store the full path of the uploading images

The table scheme is
i
path //path to the uploading imag
userid //who upload i

Now, I want to display the image path in url, it only shows the images belong to that user. User can see that image by clicking the hyperlink

Here is the code

[code
protected System.Web.UI.WebControls.HyperLink lnkAttachement

private string GetPath(int id

string sql
SqlDataReader dr

sql = "Select path From upload Where userid='" + id.ToString() + "'"
tr

dr = SqlHelper.ExecuteReader(Connection,System.Data.Com mandType.Text,sql)
if(dr.Read()

this.lnkAttachement.Text = Path.GetFileName(dr["path"].ToString())
this.lnkAttachement.NavigateUrl = stringDirectory + Server.UrlEncode(Path.GetFileName(dr["path"].ToString()))

els
dr.Close()

catc

[/code

dr.Read() cannot read the whole table and put them to the url.

How should I write it

Thanks for help
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Tom
Hi

It shows

1. only the first file name, it cannot show all file in a list form lik

a.jp
b.jp
c.jp
d.jp
.....

It only shows a.jpg even though there are many path in the DB

2. When I mouse over the path link, it shows "file:///C:/webapplication/images/a.jpg.

But, what did I want to display is http://www.mydomain.com/images/a.jpg

How can I fix those 2 problems

I am not sure what should I use to replace read(). Could you help

Thanks
Nov 18 '05 #2

P: n/a
Hi, Tom

Try the following
(HyperLink) lnkAttachement1
stringDirectory = "http://www.mydomain.com/images/"
while (dr.Read()

lnkAttachement1 = new HyperLink()
lnkAttachement1.Text = dr["path"].ToString()
lnkAttachement1.NavigateUrl = stringDirectory + Server.UrlEncode(dr["path"].ToString())
Page.Controls.Add(lnkAttachement1)
Bin Song, MCP
Nov 18 '05 #3

P: n/a
Tom

It works now!

Only 2 things

1. It displays the whole link lik

C:/webapplication/images/a.jpgC:/webapplication/images/b.jp

How can I show them lik
C:/webapplication/images/a.jp
C:/webapplication/images/b.jp

2. It shows below the upload button on the page. How can I show it on lnkAttachement1?

Because I have the tag of <asp:HyperLink ID="lnkAttachement1" Runat="server" /> insides a row of a table in aspx

Thank you for teaching me.
Nov 18 '05 #4

P: n/a
Then why not use datagrid or datalist? You can just directly bind data and add a delete button on the fly

Bin Song, MCP
Nov 18 '05 #5

P: n/a
Hi, Tom,

Glad that you finished your project. You are welcome.
I am in Canada. Programming is my job.

Bin Song, MCP
Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.