<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function Browseupl()
{
var ifUpload;
var confirmUpload;
ifUpload = ifu.document.form1;
ifUpload.myFile.click();
// confirmUpload = confirm ("You are about to upload the file " + ifUpload.myFile.value + " to the server. Do you agree to Upload?");
// if (confirmUpload)
// {
ifUpload.btnSubmit.click();
// }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<iframe src="Upload.aspx" frameborder="1" id="ifu" name="ifu" style="display:none;"></iframe>
<asp:GridView ID="grdview" runat="server" AutoGenerateColumns="false" OnRowDataBound="grdview_RowDataBound">
<Columns>
<asp:BoundField DataField="TntCode" HeaderText="Tenant Code" />
<asp:BoundField DataField="TntName" HeaderText="Tenant Name" />
<asp:BoundField DataField="FrmDt" HeaderText="From Date" />
<asp:BoundField DataField="ToDt" HeaderText="To Date" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnimg" runat="server" CommandName="UPLOAD" ImageUrl="Images/upload_file_icon.gif" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div>
</div>
</form>
</body>
</html>
gridupload.cs
public partial class gridupload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bindgrid();
//grdview.Attributes.Add("onclick", "Browseupl();");
}
}
private void Bindgrid()
{
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc;
dc = new DataColumn("TntCode");
dt.Columns.Add(dc);
dc = new DataColumn("TntName");
dt.Columns.Add(dc);
dc = new DataColumn("FrmDt");
dt.Columns.Add(dc);
dc = new DataColumn("ToDt");
dt.Columns.Add(dc);
dr = dt.NewRow();
dr["TntCode"] = "123456";
dr["TntName"] = "Jhon";
dr["FrmDt"] = "06/10/2008";
dr["ToDt"] = "09/10/2008";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["TntCode"] = "452130";
dr["TntName"] = "Peter";
dr["FrmDt"] = "08/10/2008";
dr["ToDt"] = "09/10/2008";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["TntCode"] = "452045";
dr["TntName"] = "James";
dr["FrmDt"] = "04/10/2008";
dr["ToDt"] = "09/10/2008";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["TntCode"] = "785245";
dr["TntName"] = "Ricky";
dr["FrmDt"] = "02/10/2008";
dr["ToDt"] = "09/10/2008";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["TntCode"] = "742569";
dr["TntName"] = "Martin";
dr["FrmDt"] = "07/10/2008";
dr["ToDt"] = "09/10/2008";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["TntCode"] = "124568";
dr["TntName"] = "Bill";
dr["FrmDt"] = "03/10/2008";
dr["ToDt"] = "09/10/2008";
dt.Rows.Add(dr);
grdview.DataSource = dt;
grdview.DataBind();
}
protected void grdview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[4].Attributes.Add("onclick", "Browseupl();");
}
}
}
}
Upload.aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function SubmitForm()
{
// Simply, submit the form
document.form1.submit ();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="file" runat="server" id="myFile" name="myFile" style="visibility:hidden;" />
<input type="button" runat="server" id="btnSubmit" name="btnSubmit" onclick="javascript:SubmitForm();" style="visibility:hidden;" />
<br /><asp:Label ID="lblMsg" runat="server" ForeColor="red" Font-Size="Medium" Font-Bold="true"></asp:Label>
</div>
</form>
</body>
</html>