How to list out table items in aspx?

G

Guest

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.CommandType.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
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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.
 
G

Guest

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

Bin Song, MCP
 
G

Guest

Hi, Tom,

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

Bin Song, MCP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top