jsmithr
asked on
C# DataBinding - List<structure> does not contain a property with the name 'FileName'
I am migrating VB.Net Code into a C# Project and have run into the following error:
[But you can see that there is in fact a property in my List of Type Structure called FileName?!]
Here is the code behind that Binds my List to the Repeater Control [in case it is relevant]:
I am thinking that there must be a syntax error in my Eval code, but it looks ok to me?
Jason
[But you can see that there is in fact a property in my List of Type Structure called FileName?!]
Here is the code behind that Binds my List to the Repeater Control [in case it is relevant]:
private void PopulateConventionalCoolerWalkPanel()
{
List<FSPIPartnerGlobal.stcFileInfo> li = new List<FSPIPartnerGlobal.stcFileInfo>();
li = objDirectorySearcher.GetFilesInDirectory("C:\\PartnerAccessFiles\\ConventionalCoolerWalk", "*.jpg");
if (li.Count != 0)
{
pnlConventionalCoolerWalk.Visible = true;
rptConventionalCoolerWalk.DataSource = li.GetRange(0, 5);
rptConventionalCoolerWalk.DataBind();
litConventionalCoolerWalkUpdated.Text = Convert.ToString(li[0].DateCreated);
}
li.Clear();
}
I am thinking that there must be a syntax error in my Eval code, but it looks ok to me?
Jason
ASKER
I dont know what to say. I am not defining properties in a C# Class. I am returning a Structure as a List and Binding my repeater to that list... albeit without success.
Thee must be something funny with the way C# DataBinds Lists that I do not understand.
Jason
Thee must be something funny with the way C# DataBinds Lists that I do not understand.
Jason
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yep, thats it. its a limitation of vb.net in .net 2.0. I will have to define properties in the structure like this:
Then, return that structure to the C# side, Dimension my List, then DataBind to the List.
The Eval("FullName") then works. I will post the completed code tomorrow.
Jason
Public Structure stcFileInfo
Public strFullName As String
Public DirectoryName As String
Public FileName As String
Public Extension As String
Public DateCreated As DateTime
Public DateModified As DateTime
Public AllProperties As FileInfo
Public Property FullName() As String
Get
Return strFullName
End Get
Set(ByVal value As String)
strFullName = value
End Set
End Property
End Structure
Then, return that structure to the C# side, Dimension my List, then DataBind to the List.
The Eval("FullName") then works. I will post the completed code tomorrow.
Jason
ASKER
Here is the modification to the vb.net structure that allowed me to use the C# DataBind via Eval("PropertyName").
Public Class clsDirectorySearcher
Public Structure stcFileInfo
Public strFullName As String
Public strDirectoryName As String
Public strFileName As String
Public strExtension As String
Public dtDateCreated As DateTime
Public dtDateModified As DateTime
Public fiAllProperties As FileInfo
Public Property FullName() As String
Get
Return strFullName
End Get
Set(ByVal value As String)
strFullName = value
End Set
End Property
Public Property DirectoryName() As String
Get
Return strDirectoryName
End Get
Set(ByVal value As String)
strDirectoryName = value
End Set
End Property
Public Property FileName() As String
Get
Return strFileName
End Get
Set(ByVal value As String)
strFileName = value
End Set
End Property
Public Property Extension() As String
Get
Return strExtension
End Get
Set(ByVal value As String)
strExtension = value
End Set
End Property
Public Property DateCreated() As DateTime
Get
Return dtDateCreated
End Get
Set(ByVal value As DateTime)
dtDateCreated = value
End Set
End Property
Public Property DateModified() As DateTime
Get
Return dtDateModified
End Get
Set(ByVal value As DateTime)
dtDateModified = value
End Set
End Property
Public Property AllProperties() As FileInfo
Get
Return fiAllProperties
End Get
Set(ByVal value As FileInfo)
fiAllProperties = value
End Set
End Property
End Structure
Secondaly, simpley using <%#Eval("FileName")%> will also bind the file name to your repeater's item template....
Here is my solution that worked perfectly for me:-
Markup:-
Open in new window
Code Behind:-Open in new window