在gridview中单击鼠标,选择一行 [英] Select a row on mouse click in gridview

查看:165
本文介绍了在gridview中单击鼠标,选择一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我想在鼠标点击gridview中选择一行。

I have a problem, I want to select a row in gridview on mouse click.

我的代码是:

protected void PeopleGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvdetails, "Select$" + e.Row.RowIndex);
        }
    }

它不工作。我不知道为什么?

it is not working. i don't know why?

plz建议我。


推荐答案

找到了关于

在GridView标记下的ASPX页面中添加:

Found the tutorial about ASP.Net select row in gridview
In ASPX page under GridView tag add:

<SelectedRowStyle BackColor="Orange" />

在代码中,尝试以下操作:

In code behind try the following:

protected override void Render(System.Web.UI.HtmlTextWriter writer) 
{ 
    foreach (GridViewRow row in PeopleGridView.Rows) { 
        if (row.RowType == DataControlRowType.DataRow) { 
            row.Attributes["onmouseover"] =  
               "this.style.cursor='hand';this.style.textDecoration='underline';"; 
            row.Attributes["onmouseout"] =  
               "this.style.textDecoration='none';"; 
            // Set the last parameter to True 
            // to register for event validation. 
            row.Attributes["onclick"] =  
             ClientScript.GetPostBackClientHyperlink(PeopleGridView, 
                "Select$" + row.DataItemIndex, true); 
        } 
    } 
    base.Render(writer); 
}

然后你可以使用RowCommand来捕获这个事件。 p>

You can then catch this event using the RowCommand (something like).

private void PeopleGridView_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Select") { 
        // Get the list of customers from the session  
        List<Customer> customerList = 
                 Session["Customers"] as List<Customer>;

         Debug.WriteLine(customerList[Convert.ToInt32(e.CommandArgument)].LastName);
    } 
}

这篇关于在gridview中单击鼠标,选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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