I am working on a project where I need to display a gridview containing information about all the employees. When a user selects a particular employee, I want to open a new page or window that shows all the details of that employee with options for editing, deleting, and updating. After completing the transaction, the user should be able to return to the previous page with the gridview displaying all employees. (I am using VB language)
<asp:TemplateField Visible="true" headertext="Select">
<ItemTemplate>
<asp:HiddenField ID="hdID01" runat="server" Value='<%# Eval ("PersonnelID") %>' />
</ItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkSelect" runat="server" CommandName="select" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
------ code behind ----
Protected Overridable Sub Grid_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' Click to highlight row
Dim lnkSelect As Control = e.Row.FindControl("lnkSelect")
If lnkSelect IsNot Nothing Then
Dim click As New StringBuilder()
click.AppendLine(GridView1.Page.ClientScript.GetPostBackClientHyperlink(lnkSelect, String.Empty))
click.AppendLine(String.Format("onGridViewRowSelected('{0}')", e.Row.RowIndex))
e.Row.Attributes.Add("onclick", click.ToString())
End If
End If
End Sub
------ Javascript -----
<script type="text/javascript">
var selectedRowIndex = null;
function onGridViewRowSelected(rowIndex) {
selectedRowIndex = rowIndex;
}
function editItem() {
if (selectedRowIndex == null) return;
var cell = gridView.rows[parseInt(selectedRowIndex) + 1].cells[0];
var hidID = cell.childNodes[0];
window.open('mg_edit.aspx?id=' + hidID.value);
}
When I select an item, nothing happens. I'm stuck and need some assistance!