Solved

RowDataBound

Posted on 2006-06-29
8
1,761 Views
Last Modified: 2008-01-09
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.



0
Comment
Question by:Neal Hartman
8 Comments
 
LVL 7

Expert Comment

by:kGenius
ID: 17010501
You can read this in http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21069007.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
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17010502
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
0
 
LVL 1

Author Comment

by:Neal Hartman
ID: 17011176
I meant: How do I change the ImageURL in the Templatefield from the RowdataBound Sub?
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17012320

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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Neal Hartman
ID: 17012617
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)
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17012653
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"
0
 
LVL 1

Author Comment

by:Neal Hartman
ID: 17012777
Still not finding it. I think I have to work with theTempletfield somehow.
0
 
LVL 9

Accepted Solution

by:
bele04 earned 500 total points
ID: 17015153
you can just use CType(e.Row.FindControl("Name_Of_Your_Image"), Image).ImageURL = "path to pic.gif"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now