rowdatabound in gridview in asp.net..

Posted by Gopal_nivas under ASP.NET on 10/4/2010 | Points: 10 | Views : 9612 | Status : [Member] | Replies : 2
hi..

i want to display images inside gridview..

i was stored the name of the images in database..

my table is like this..

id un imgname createdvy
1 ram a.jpg admin
2 raj b.jpg admin
3 sam c.jpg admin

here i want to display the images inside the gridview.
i was taking the image values in dataset and assign the values in imagebutton inside gridview..

i was getting the three values and also i was find the imgbutton control inside gridview..

but my code in rowdatabound
string Thumb;
dataset ds=new dataset();
da.fill(ds);
ImageButton ibtn_CatImage = (ImageButton)e.Row.FindControl("ibtn_CatImage");

for(int i=0;ds.tables[0].rows.count;i++)
{
string foldername=ds.Tables[0].Rows[val]["imgname"];

string path = ConfigurationManager.AppSettings["path"] + @"ImageResource/CategoryThumbImages/" + foldername+ @"/" + ibtn_CatImage.ImageUrl;
Thumb = path;
ibtn_CatImage.ImageUrl = Thumb;
}

so here the values are concardinated and it doesnot show the images inside the gridview..


how to tackle this problem..

need ur suggestions with example..

regards
gopal.s




Responses

Posted by: T.saravanan on: 10/4/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Gopal,

http://msdn.microsoft.com/en-us/library/aa479350.aspx

Refer this link its will helpful.

Cheers :)

Thanks,
T.Saravanan

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 10/4/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Good Evening Gopal_nivas

I am have scanned your code and i see you are looping and i am not sure why you have a loop there and another thing its really not a good idea to store images inside a table, better store the path of the image , this is a perfomance hit.

First of all , you want to display an image in a Gridview, which is possible, You see i dont undestand why you have this

or(int i=0;ds.tables[0].rows.count;i++) 

{
string foldername=ds.Tables[0].Rows[val]["imgname"];

string path = ConfigurationManager.AppSettings["path"] + @"ImageResource/CategoryThumbImages/" + foldername+ @"/" + ibtn_CatImage.ImageUrl;
Thumb = path;
ibtn_CatImage.ImageUrl = Thumb;
}


What you should have done is to bind your dataset to the grid, for each corresponding row it will place an image or Junk Data in that field, then now if you can display other data and a strange data on the image field then you can do a screenshot and we will help you further, remeber always when you have a problem , break it down into part and it will be easy to get a solution.

Thank you for posting at Dotnetfunda

Vuyiswa Maseko


Thank you for posting at Dotnetfunda
[Administrator]

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response