This is a migrated thread and some comments may be shown as answers.

[Solved] How display images from sql datbase using radList view

1 Answer 281 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Missing User
Missing User asked on 21 Jan 2013, 06:00 PM
I am using c# and sql database.
Database contains two filed 1.ID - Int
                                             2.Picture - Image
I had binded the database to radList view ,picture is set as Display member and ID is set as value member.
Problem is pictures are not showing .How to display pictures ?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Jan 2013, 09:35 AM
Hi Anoop,

Thank you for writing.

To assign an image to ListViewData item from your underlying DataRow, you should use the ItemDataBound event as explained in this help article. Here is a small sample:
public Form1()
{
    InitializeComponent();
 
    DataTable t = new DataTable();
    t.Columns.Add("ID");
    t.Columns.Add("Image", typeof(Image));
 
    t.Rows.Add("1", Image.FromFile(@"C:\Program Files (x86)\Telerik\RadControls for WinForms Q3 2012\Examples\QuickStart\Resources\BE.png"));
    t.Rows.Add("1", Image.FromFile(@"C:\Program Files (x86)\Telerik\RadControls for WinForms Q3 2012\Examples\QuickStart\Resources\BR.png"));
    t.Rows.Add("1", Image.FromFile(@"C:\Program Files (x86)\Telerik\RadControls for WinForms Q3 2012\Examples\QuickStart\Resources\BUL.png"));
    radListView1.ItemDataBound += radListView1_ItemDataBound;
 
    radListView1.DataSource = t;
    radListView1.DisplayMember = "ID";
}
 
void radListView1_ItemDataBound(object sender, Telerik.WinControls.UI.ListViewItemEventArgs e)
{
    DataRowView rowView = e.Item.DataBoundItem as DataRowView;
    e.Item.Image = rowView.Row["Image"] as Image;
}

I hope this helps.
 

Regards,
Stefan
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
ListView
Asked by
Missing User
Answers by
Stefan
Telerik team
Share this question
or