ASP.NET DataGrid Issue
-
Hello all, I am using the dataGrid control to display inventory form a database. The very last field in the database has just an HTML text string somehting like "
", when the dataGrid hits this field everything works great. I am trying to fine tune it a little, so when an image of the product does not exist, who do I get an alternate image to show in the dataGrid? Heeler
-
Hello all, I am using the dataGrid control to display inventory form a database. The very last field in the database has just an HTML text string somehting like "
", when the dataGrid hits this field everything works great. I am trying to fine tune it a little, so when an image of the product does not exist, who do I get an alternate image to show in the dataGrid? Heeler
Does your datagrid have a Image Server control to hold the image? If so, you can do somethign like this:
If System.IO.File.Exists("PATHTOIMAGE") = False Then
CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOBLANKIMAGE"
Else
CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOIMAGE"
End IfMyDataGrid = Your data grid name PATHTOIMAGE = the path to the image taken from the DB ROW = the current row you are working with on the datagrid IMAGEHOLDERCONTROLNAME = the name of the control to hold the image inside the dg PATHTOBLANKIMAGE = the path to the blank image to use Jon G www.Gizmocoder.com
-
Does your datagrid have a Image Server control to hold the image? If so, you can do somethign like this:
If System.IO.File.Exists("PATHTOIMAGE") = False Then
CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOBLANKIMAGE"
Else
CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOIMAGE"
End IfMyDataGrid = Your data grid name PATHTOIMAGE = the path to the image taken from the DB ROW = the current row you are working with on the datagrid IMAGEHOLDERCONTROLNAME = the name of the control to hold the image inside the dg PATHTOBLANKIMAGE = the path to the blank image to use Jon G www.Gizmocoder.com
No, there isnt a server control to house the image, my grid gets bound automatically by the data sources default view. So basically I do not build the datagrid programatically... So when I want to display other forms of the data I just edit the SQL string... Heeler
-
No, there isnt a server control to house the image, my grid gets bound automatically by the data sources default view. So basically I do not build the datagrid programatically... So when I want to display other forms of the data I just edit the SQL string... Heeler
Then the only way I can see you making this possible is by making a specific image reserved for blank entries, and then setting the path in the SQL server DB to that blank image when needed. Jon G www.Gizmocoder.com
-
Then the only way I can see you making this possible is by making a specific image reserved for blank entries, and then setting the path in the SQL server DB to that blank image when needed. Jon G www.Gizmocoder.com
-
Hello all, I am using the dataGrid control to display inventory form a database. The very last field in the database has just an HTML text string somehting like "
", when the dataGrid hits this field everything works great. I am trying to fine tune it a little, so when an image of the product does not exist, who do I get an alternate image to show in the dataGrid? Heeler
Maybe this could help you: Code-behind: ... C#: public bool IsImageAvailable(String photo) { String path = "name_of_file_here"; return File.Exists(Server.MapPath(path)); }
-
Maybe this could help you: Code-behind: ... C#: public bool IsImageAvailable(String photo) { String path = "name_of_file_here"; return File.Exists(Server.MapPath(path)); }
-
Thanks WiB, I used your C# method and modified the way the database inserts that field. Thank you for your help... The ASP side wouldn't work because of the way the Grid was bound. But I used part of your code so thank you very much. Actually thanks to everyone that replied... :) Heeler