Hi Vanessa,
Refer below code.
HTML
Default
<div style="height: 435px; width: 1228px; overflow: auto;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True"
OnSelectedIndexChanged="OnSelectedIndexChanged" OnPageIndexChanging="OnPageIndexChanging"
Width="1500px" Height="188px" PageSize="3" AllowPaging="true">
<AlternatingRowStyle Font-Size="Small" BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDetails" runat="server" Text="Edit" PostBackUrl='<%# "~/PENRO_Records/PENRO_RecordForm.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>
</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>
PENRO_RecordForm
<asp:TextBox ID="txtPENTransCode" runat="server" />
<asp:Label ID="lbNameofService" runat="server" />
Code
C#
Default
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 OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGrid();
}
PENRO_RecordForm
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
Default
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 OnPageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
BindGrid()
End Sub
PENRO_RecordForm
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