<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
code behind section
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
public class Person
{
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
public string ImageUrl
{
get;
set;
}
public Person(int Id, string Name, string ImageUrl)
{
this.Id = Id;
this.Name = Name;
this.ImageUrl = ImageUrl;
}
}
//Binding some sample data to the GridView
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Populating some dummy data. In reality, you should populate these
//from the database
IList items = new ArrayList();
items.Add(new Person(1, "Peter", "~/images/ab.jpg"));
items.Add(new Person(2, "John", "~/images/cd.jpg"));
items.Add(new Person(3, "Shubho", "~/images/ef.jpg"));
GridView1.DataSource = items;
GridView1.DataBind();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
string ImageUrl = (string)e.CommandArgument;
string physicalImagePath = Server.MapPath(ImageUrl);
if (File.Exists(physicalImagePath))
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(physicalImagePath));
Response.ContentType = "image/jpg";
Response.TransmitFile(physicalImagePath);
Response.Flush();
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton link = e.Row.FindControl("LinkButton1") as LinkButton;
if (link != null)
{
link.CommandArgument = ((Person)e.Row.DataItem).ImageUrl.ToString();
}
}
}
}
Manikavelu VelayuthamPosted Aug 25, 2010, 1:34 AM
SqlConnection cn = new SqlConnection("data source=.;database=biblio;uid=admin;pwd=pw");
SqlDataAdapter da = new SqlDataAdapter("Select top 50 Author, Year_born from Authors Where Year_born is not null", cn);
DataSet ds = new DataSet();
da.Fill(ds, "Authors");
DataGrid1.DataSource = ds.Tables["Authors"];
DataGrid1.DataBind();
Manikavelu VelayuthamPosted Aug 25, 2010, 1:33 AM
Sub Page_Load(Src As Object, e As EventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter ' Create a connection to the "pubs" SQL database located on the
' local computer.
myConnection = New SqlConnection("server=localhost;" _
& "database=pubs;Trusted_Connection=Yes")
' Connect to the SQL database using a SQL SELECT query to get all
' the data from the "Authors" table.
myCommand = new SqlDataAdapter("SELECT * FROM Authors", _
myConnection)
' Create and fill a DataSet.
Dim ds As DataSet = new DataSet()
myCommand.Fill(ds)
' Bind MyDataGrid to the DataSet. MyDataGrid is the
' ID for the DataGrid control in the HTML section.
MyDataGrid.DataSource = ds
MyDataGrid.DataBind()
End Sub
aman sohalPosted Aug 24, 2010, 10:48 PM
Manikavelu VelayuthamPosted Aug 24, 2010, 4:27 AM