如何创建一个可单击的gridview行? [英] How to create a gridview row clickable?

查看:53
本文介绍了如何创建一个可单击的gridview行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个gridview行,其中的整个行都是可单击的,当我单击该行的任何位置时,它将打开另一个包含行信息的aspx页面.

I want to create a gridview row where the whole row is clickable and when I click anywhere on the row it open another aspx page with the rows information.

我正在使用asp.net和C#. 谁能帮我.预先感谢.

I am using asp.net and C#. Can anyone help me please. Thanks in advance.

推荐答案

只需在RowDataBound上的以下代码中调用即可在Gridview行上的任意位置单击以触发SelectedIndexChanged事件

Just call below code on RowDataBound to click anywhere on Gridview row to fire SelectedIndexChanged event

您必须执行<%@ Page EnableEventValidation="False" %>

protected void grdYourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{   
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Attaching one onclick event for the entire row, so that it will
        // fire SelectedIndexChanged, while we click anywhere on the row.
        e.Row.Attributes["onclick"] = 
          ClientScript.GetPostBackClientHyperlink(this.grdYourGrid, "Select$" + e.Row.RowIndex);
    }
}

这篇关于如何创建一个可单击的gridview行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆