Hi Vanessa,
Refer below sample code.
HTML
Home
<asp:Button ID="btnShowPopup" runat="server" Text="Show Popup" />
<div id="dialog" style="display: none">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True"
OnSelectedIndexChanged="OnSelectedIndexChanged" OnPageIndexChanging="OnPageIndexChanging"
Width="1500px" Height="188px" PageSize="3" AllowPaging="true" DataKeyNames="PENTransCode">
<AlternatingRowStyle Font-Size="Small" BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDetails" runat="server" Text="Edit"
PostBackUrl='<%# "~/Default.aspx?RowIndex=" + Container.DataItemIndex %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="500px" DataField="PENTransCode" HeaderText="PENTransCode">
<HeaderStyle ForeColor="#3366CC" />
<ItemStyle Width="500px" />
</asp:BoundField>
<asp:TemplateField HeaderText="NameofService">
<ItemTemplate>
<asp:Label ID="lbNameofService" runat="server" Text='<%# Eval("NameofService") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="lnkDownload" runat="server" Text="Download" OnClick="DownloadFile"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle Font-Size="Small" />
<HeaderStyle ForeColor="#996633" Font-Size="Small" BackColor="#FFCC66"
BorderColor="#666666" BorderWidth="1px" Height="30px"
HorizontalAlign="Center" VerticalAlign="Middle" />
<RowStyle Font-Size="Small" BackColor="White" />
</asp:GridView>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnShowPopup]").click(function () {
ShowPopup();
return false;
});
});
function ShowPopup() {
$("#dialog").dialog({
title: "Returned Accomplishment Reports",
width: 250,
buttons: {
Ok: function () {
$(this).dialog('close');
}
},
modal: true
});
}
</script>
Default
<asp:TextBox ID="txtPENTransCode" runat="server" />
<asp:Label ID="lbNameofService" runat="server" />
Code
Home
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("PENTransCode"),
new DataColumn("NameofService")
});
dt.Rows.Add(1, "Service 1");
dt.Rows.Add(2, "Service 2");
dt.Rows.Add(3, "Service 3");
dt.Rows.Add(4, "Service 4");
dt.Rows.Add(5, "Service 5");
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DownloadFile(object sender, EventArgs e)
{
Button lnkbtn = sender as Button;
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
string filePath = GridView1.DataKeys[gvrow.RowIndex].Value.ToString();
Response.ContentType = ContentType;
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
Response.TransmitFile(Server.MapPath(filePath));
Response.End();
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGrid();
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup();", true);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {
New DataColumn("PENTransCode"),
New DataColumn("NameofService")})
dt.Rows.Add(1, "Service 1")
dt.Rows.Add(2, "Service 2")
dt.Rows.Add(3, "Service 3")
dt.Rows.Add(4, "Service 4")
dt.Rows.Add(5, "Service 5")
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim lnkbtn As Button = TryCast(sender, Button)
Dim gvrow As GridViewRow = TryCast(lnkbtn.NamingContainer, GridViewRow)
Dim filePath As String = GridView1.DataKeys(gvrow.RowIndex).Value.ToString
Response.ContentType = ContentType
Response.AddHeader("Content-Disposition", "attachment;filename=" & filePath)
Response.TransmitFile(Server.MapPath(filePath))
Response.End()
End Sub
Protected Sub OnPageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
BindGrid()
End Sub
Default
C#
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.PreviousPage != null)
{
int rowIndex = int.Parse(Request.QueryString["RowIndex"]);
GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
GridViewRow row = GridView1.Rows[rowIndex % GridView1.PageSize];
txtPENTransCode.Text = row.Cells[1].Text;
lbNameofService.Text = ((Label)row.FindControl("lbNameofService")).Text;
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Me.Page.PreviousPage IsNot Nothing Then
Dim rowIndex As Integer = Integer.Parse(Request.QueryString("RowIndex"))
Dim GridView1 As GridView = DirectCast(Me.Page.PreviousPage.FindControl("GridView1"), GridView)
Dim row As GridViewRow = GridView1.Rows(rowIndex Mod GridView1.PageSize)
txtPENTransCode.Text = row.Cells(1).Text
lbNameofService.Text = CType(row.FindControl("lbNameofService"), Label).Text
End If
End Sub
Screenshot