Solved

RowDataBound

Posted on 2006-06-29
8
1,758 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

16 Experts available now in Live!

Get 1:1 Help Now