I am trying to create a website that can let user to search images. I created a local database ( a folder with a few images) for image, and there are 3 columns for data: title, picURL and keyword.
At my default page, I set up a textbox and Search button. What I did is:
string query = "SELECT picURL FROM imagedatabase WHERE [keyword] = '" + keyword + "'";
[keyword] is one of the name of the column and the keyword is the one user types in the textbox.
So now if I find an image in the database, then I got its URL. But how can I display the image in .aspx? like are they any specific command or something I can do开发者_开发百科 to display the image?
thanks
EDIT:
So I changed the code like this:
In my homepage.aspx, I added in this:
<asp:Image ID="Image1" runat="server" ImageUrl="Image1.ImageUrl" />
and in my homepage.aspx.cs, I wrote this:
protected void btnImageSearch_Click(object sender, EventArgs e)
{
ImageSearch();
}
private void ImageSearch()
{
string ImageURL;
ImageURL= Process.KeywordSearch(txtSearch.Text);
Image1.ImageUrl = ImageURL;
}
and in my Process.cs, I wrote this:
public static string KeywordSearch(string keyword)
{
string query = "SELECT imagepath FROM tbimage WHERE [title] = '" + keyword + "'";
return query;
}
After I wrote all these, I tried to debug. I typed in the keyword, but no image showed up. I know in Process.cs, query will get the URL in database (the URL is like C:\ ....) So Image1.ImageUrl should equal to that URL. but then I am wondering if
can this really get the Image1.ImageUrl? because no image showed up.
Hope somebody can help and thanks
for this you can use Image
control of asp.net and set its ImageUrl
property to your image url. Like this
<asp:Image ID="Image1" runat="server" />
and in CodeBehind
Image1.ImageUrl = query;
Do as follow
1 Save or move your images into a folder.
2 Add this folder into your solution or project.
3 Take image name only (not physical path) from your database.
4 Set ImageUrl property to virtual path.
精彩评论