Solved

RowDataBound

Posted on 2006-06-29
8
1,763 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 9

Expert Comment

by:zaghaghi
ID: 17012320

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

0
 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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