how to display folder images in gridview

Posted by Vanamalisowjanya under ASP.NET on 10/27/2011 | Points: 10 | Views : 5565 | Status : [Member] | Replies : 2
hi,,

in my local drive contain some images now i want to display that images in frontd gridview how write the code ...................can u help me

vanamali .sowjanya


Responses

Posted by: Abdulhaknet on: 10/27/2011 [Member] Starter | Points: 25

Up
0
Down
Please try the code below


DataTable dt = new DataTable();
dt.Columns.Add("MyImages", typeof(string));
DataRow dr;
int i = 1;
foreach (string file in Directory.GetFiles(Server.MapPath(@"Myfolder\")))
{
dr = dt.NewRow();
dr[0] = ResolveUrl(file);
dt.Rows.Add(dr);
i += 1;
}
GridView1.DataSource = dt;
GridView1.DataBind();



-----------------------------------

protected string ResolveUrl(string url)
{

if (url != null && url.Length > 0)

return ("~/" + url);

else return null;

}

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

Posted by: Sriramnandha on: 10/27/2011 [Member] Starter | Points: 25

Up
0
Down
do the following Steps:
Perform the following actions:
1.Uncheck the Auto-generate field
2.Use two BoundFields for UserName and Country
3.Set the Header Text and DataField (field name in database)
4.Use ImageField for the image and set DataImageUrlField = ImageFieldName (ColumnName)
5.Click OK

public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
conn.ConnectionString
= "Data Source=MyServer; Integrated Security=True; database=test";
Load_GridData(); // call method below
}
void Load_GridData()
{
conn.Open(); // open the connection
SqlDataAdapter Sqa = new SqlDataAdapter("select * from picture", conn);
DataSet ds = new DataSet();
Sqa.Fill(ds); // fill the dataset
GridView1.DataSource = ds; // give data to GridView
GridView1.DataBind();
conn.Close();
}
}
Hope this will help..
Let me know any questions..
Regards
Sriram.R

sriram

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

Login to post response