Get GridView selected row DataKey in Javascript

转载 2013年12月06日 00:20:24
<asp:TemplateField ShowHeader="False">    <ItemTemplate>      <asp:HiddenField ID="hdID" runat="server" Value='<%# Eval("JobID") %>' />    </ItemTemplate></asp:TemplateField><asp:TemplateField Visible="False">    <ItemTemplate>      <asp:LinkButton ID="lnkSelect" runat="server" CommandName="select" Text="Select" />    </ItemTemplate></asp:TemplateField>

Then on the OnRowDataBind have code to set the selected row

protected virtual void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.DataRow)
        // Click to highlight row
        Control lnkSelect = e.Row.FindControl("lnkSelect");
        if (lnkSelect != null)
            StringBuilder click = new StringBuilder();
            click.AppendLine(m_View.Page.ClientScript.GetPostBackClientHyperlink(lnkSelect, String.Empty));
            click.AppendLine(String.Format("onGridViewRowSelected('{0}')", e.Row.RowIndex));
            e.Row.Attributes.Add("onclick", click.ToString());

And then in the Javascript I have code like this

<script type="text/javascript">

var selectedRowIndex = null;

function onGridViewRowSelected(rowIndex)
    selectedRowIndex = rowIndex;

function editItem()
    if (selectedRowIndex == null) return;

    var gridView = document.getElementById('<%= GridView1.ClientID %>');                
    var cell = gridView.rows[parseInt(selectedRowIndex)+1].cells[0];        
    var hidID = cell.childNodes[0];   'JobTypeEdit.aspx?id=' + hidID.value);



How to get the Values of Selected Row from a Gridview using ASP.NET

In this Article you can learn how to get the values of selected row from a Gridview and display the ...

ASP.NET: Display GridView Row Details in Modal Popup using Twitter Bootstrap

There are several ways in which you can display details of a gridview row in order for the user to h...


protected void btnOperate_Click(object sender, EventArgs e) { string id = null; ...

gridview insert row

  • 2011-03-02 16:04
  • 371KB
  • 下载

Android gridview keep item selected


DevExpress ASPxListBox can't get selected items after postback

page code

Getting all selected rows in ADF Table with multiple rows selection enabled

Getting all selected rows in ADF Table with multiple rows selection enabled When we build a web a...