开发者

Open a new window with specific record details from a select row ID in a datagrid

开发者 https://www.devze.com 2023-01-28 05:37 出处:网络
I have a gridview displaying all employees. Upon selecting an employee, I\'d like to open a new page or window that would display all of the information for that employee with the option to edit/delet

I have a gridview displaying all employees. Upon selecting an employee, I'd like to open a new page or window that would display all of the information for that employee with the option to edit/delete/update. Once this transaction is complete, return to previous page with gridview of all employees. ((language I'm usings is VB)) ----- code in gridview ---

<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 edit开发者_C百科Item() {
        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);
    } 

Nothing happens when selected. ??? I need help!


One of these links should give you a better direction about what you are trying to accomplish with a GridView:

http://www.codeproject.com/KB/webforms/GridViewConfirmDelete.aspx http://weblogs.asp.net/scottgu/archive/2006/01/02/434362.aspx

Or, you may want to consider using a ListView control if you are using 3.5 or higher:

http://basgun.wordpress.com/2008/01/06/onclick-tooltip-listview/

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消