need help on Image control in the datalist
-
Hi, I have a very interesting problem, my code doesn't show any errors or exceptions, but when I'm running the web-page, it still doesn't work properly. I want to bind an image on an image control, which is inside the Datalist and Datalist is inside the DetailsView. When I'm debugging the code, it shows me the imageURL path very well, but doesn't show me the image in the browser. My Select statement si : SelectCommand="SELECT [Source] FROM [Images] WHERE ([NID] = @NID) Here is my code on page load:
string nID = Request.QueryString["nID"].ToString(); DataView view = (DataView)ImagesSqlDataSource.Select(DataSourceSelectArguments.Empty); int count = (int)view.Table.Rows.Count; Label username = (Label)NDetailsView.FindControl("UsernameLabel"); DataList ImagesDataList = (DataList)NDetailsView.FindControl("ImagesDataList"); for (int i = 0; i < count; i++) { Image image = (Image)ImagesDataList.Items[i].FindControl("ImageControl"); string imagename = (string)view.Table.Rows[i].ItemArray[0]; image.ImageUrl = Request.PhysicalApplicationPath + @"Images\" + username.Text + "\\" + nID + "\\" + imagename; }
Thank you -
Hi, I have a very interesting problem, my code doesn't show any errors or exceptions, but when I'm running the web-page, it still doesn't work properly. I want to bind an image on an image control, which is inside the Datalist and Datalist is inside the DetailsView. When I'm debugging the code, it shows me the imageURL path very well, but doesn't show me the image in the browser. My Select statement si : SelectCommand="SELECT [Source] FROM [Images] WHERE ([NID] = @NID) Here is my code on page load:
string nID = Request.QueryString["nID"].ToString(); DataView view = (DataView)ImagesSqlDataSource.Select(DataSourceSelectArguments.Empty); int count = (int)view.Table.Rows.Count; Label username = (Label)NDetailsView.FindControl("UsernameLabel"); DataList ImagesDataList = (DataList)NDetailsView.FindControl("ImagesDataList"); for (int i = 0; i < count; i++) { Image image = (Image)ImagesDataList.Items[i].FindControl("ImageControl"); string imagename = (string)view.Table.Rows[i].ItemArray[0]; image.ImageUrl = Request.PhysicalApplicationPath + @"Images\" + username.Text + "\\" + nID + "\\" + imagename; }
Thank youYou are using Request.PhysicalApplicationPath which is not correct. This will translate to c:\inetputb\wwwroot or something like that. Easiest way to fix the issue is:
image.ImageUrl = new StringBuilder(@"~/Images/").Append(username.Text)
.Append(nID).Append("/").Append(imagename).ToString();Co-Author ASP.NET AJAX in Action
-
You are using Request.PhysicalApplicationPath which is not correct. This will translate to c:\inetputb\wwwroot or something like that. Easiest way to fix the issue is:
image.ImageUrl = new StringBuilder(@"~/Images/").Append(username.Text)
.Append(nID).Append("/").Append(imagename).ToString();Co-Author ASP.NET AJAX in Action