Link to home
Start Free TrialLog in
Avatar of Neal Hartman
Neal HartmanFlag for United States of America

asked on

RowDataBound

In a Gridview I have a column with a Templetfield that has an imaige of a floppy disk. In the RowDataBound event I have e.Row.Cells(0).Attributes.Add(.... stuff.

What I would like to do is, if the file to be downloaded does not exists, change the image to something else.



Avatar of kGenius
kGenius
Flag of Belgium image

You can read this in https://www.experts-exchange.com/questions/21069007/ASP-VB-NET-Check-if-File-exists.html

Imports System.IO

Then, you can use the shared Exists() method to look for a specific file. With
the File class, you pass in the path as a string, like so:

If File.Exists("c:\myfile.txt") Then
'do something  
Else
'do something  
End If
Avatar of Hamed Zaghaghi
in RowDataBound Event

for each row check if file exist then change image to exist, and if file doean't exist change the image to other
Avatar of Neal Hartman

ASKER

I meant: How do I change the ImageURL in the Templatefield from the RowdataBound Sub?

CType(e.Row.Cells(0).Controls(0), Image).ImageURL = "available.gif"

System.ArgumentOutOfRangeException was unhandled by user code
  Message="Specified argument was out of the range of valid values.
Parameter name: index"
  ParamName="index"
  Source="System.Web"
  StackTrace:
       at System.Web.UI.ControlCollection.get_Item(Int32 index)
       at ResultsMain.gvDownloadsTop_RowDataBound(Object sender, GridViewRowEventArgs e) in C:\VB\VBSOURCE\Visual Studio 2005\WebSites\EM2000Net\results.aspx.vb:line 1530
       at System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e)
       at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
       at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
       at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at System.Web.UI.WebControls.GridView.DataBind()
       at ResultsMain.Page_Load(Object sender, EventArgs e) in C:\VB\VBSOURCE\Visual Studio 2005\WebSites\EM2000Net\results.aspx.vb:line 766
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
i = the number of cell
j = the number of control in cell

CType(e.Row.Cells(i).Controls(j), Image).ImageURL = "available.gif"

also you can use

CType(e.Row.Cells(0).FindControl("ImageControlName"), Image).ImageURL = "available.gif"
Still not finding it. I think I have to work with theTempletfield somehow.
ASKER CERTIFIED SOLUTION
Avatar of bele04
bele04

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial