?
Solved

RowDataBound

Posted on 2006-06-29
8
Medium Priority
?
1,786 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 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