?
Solved

List view databinding, asp.net, c#

Posted on 2009-02-22
4
Medium Priority
?
322 Views
Last Modified: 2013-12-17
hi,

I have the following code

protected void dlPaging_ItemCreated(object sender, ListViewItemEventArgs  e)
    {
        Image image = (Image)e.Item.FindControl("imgStartUpImagePath");
        DbDataRecord url = (DbDataRecord)e.Item.DataItem;
           

        string filePath = url["StartUpImagePath"].ToString(); ;

        FileInfo fileInfo = new FileInfo(filePath);

        //append the '\' before the directory name

        DirectoryInfo directoryInfo = new DirectoryInfo(fileInfo.DirectoryName);

        string parentDir = string.Format(@"\{0}", directoryInfo.Parent);
        image.ImageUrl = "~" + (filePath.Substring(filePath.IndexOf(parentDir)));
    }

but get an error System does not contain a defination for dataitem. on line    
DbDataRecord url = (DbDataRecord)e.Item.DataItem;

so what do i use instead of a dataitem in a list view

Thanks,

R8VI
0
Comment
Question by:R8VI
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
jabcoco earned 2000 total points
ID: 23704984
Hi, let's try this and let me know.
    void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
    {
        ListViewItem eitm = e.Item;
        objectMyColumnValue = ((DataRowView)(((ListViewDataItem)(eitm)).DataItem)).Row["YourColumnName"];
    }

Open in new window

0
 
LVL 10

Expert Comment

by:jabcoco
ID: 23704988
oups, should read "object MyColumnValue"
0
 

Author Comment

by:R8VI
ID: 23705249
Hi,

So I have changed it to the following now

 protected void dlPaging_ItemCreated(object sender, ListViewItemEventArgs e)
    {
        ListViewItem eitm = e.Item;
        object MyColumnValue = ((DataRowView)(((ListViewDataItem)(eitm)).DataItem)).Row["YourColumnName"];

        Image image = (Image)e.Item.FindControl("imgStartUpImagePath");
        string filePath = url["StartUpImagePath"].ToString(); ;

        FileInfo fileInfo = new FileInfo(filePath);

        //append the '\' before the directory name

        DirectoryInfo directoryInfo = new DirectoryInfo(fileInfo.DirectoryName);

        string parentDir = string.Format(@"\{0}", directoryInfo.Parent);
        image.ImageUrl = "~" + (filePath.Substring(filePath.IndexOf(parentDir)));
    }

but what do i use instead of url in line  string filePath = url["StartUpImagePath"].ToString(); ;

thanks,

R8VI
0
 

Author Comment

by:R8VI
ID: 23705271
sorry i was being silly got it to work

thanks,

R8VI
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 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