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];        
    window.open('JobTypeEdit.aspx?id=' + hidID.value);
}

</script>

相关文章推荐

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...

GridView批处理通过DataKey取行参数

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

GridView设置ImageView的setSelected为true失败解决方案

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...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)