Check if image exists before binding to datagrid.

Discussion in 'ASP.NET / ASP.NET Core' started by Frankb, Nov 24, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello I am struggeling with an error when trying to verify a image files existance before binding it to a datagrid.
    The error message I am recieving on the if statement is
    BC30311: Value of type 'System.Data.DataRowCollection' cannot be converted to 'String'.
    I don't see why its trying to convert to a string.
    here is the code.

    Sub BindGrid()
    Dim DS As DataSet
    Dim MyCommand As oledbDataAdapter
    MyCommand = new oledbDataAdapter("select * from mytable", MyConnection)

    DS = new DataSet()
    MyCommand.Fill(DS, "mytable")
    dim i as integer
    for i=0 to DS.Tables("mytable").Rows.Count-1
    IF(System.IO.File.Exists(Server.MapPath(DS.Tables("mytable").Rows["picture"])))Then
    'picture available
    Else
    DS.Tables("mytable").Rows["picture"]="images/none.jpg"
    end if
    Next

    MyDataGrid.DataSource=DS.Tables("mytable").DefaultView
    MyDataGrid.DataBind()
    End Sub

    and datagrid image section
    <asp:Image id=Image1 runat="server" NAME="Image1" Height = 75 Width =100 ImageUrl='<%# DataBinder.Eval(Container.DataItem, "picture") %>'>

    any help is greatly appreciated.
    Thanks
     
  2. I collection is an array. you cant put an array in a string. Try to be more specific when referencing the collection.

    System.Data.DataRowCollection.Item(ByVal index As Integer) Will get the row at the specified index.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page