asp.net GridView选择索引已更改 [英] asp.net GridView selected index changed

查看:99
本文介绍了asp.net GridView选择索引已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我在gridview中使用自动生成的选择按钮并单击它时,事件GridView_selected索引已更改被触发。



但是我想在行点击时点击这个事件而不是点击选择按钮。



我怎样才能继续?

解决方案

请参考我的回答 - Data GridView选择的索引改变了触发问题ASP.NET [ ^ ]。



更新

似乎没有选择按钮,事件就不会触发。所以,请在下面进行操作。



  1. 制作 AutoGenerateSelectButton =True

    并写入 OnSelectedIndexChanged 事件。

     AutoGenerateSelectButton =True
    OnSelectedIndexChanged =GridView1_SelectedIndexChanged

  2. RowDataBound 事件中添加以下代码。

    < pre lang =cs> if (e.Row.RowType == DataControlRowType.Header)
    {
    e.Row.Cells [< span class =code-digit> 0 ]。Style.Add(HtmlTextWriterStyle.Display, none );
    }

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e .Row.Cells [ 0 ]。Style.Add(HtmlTextWriterStyle.Display, );

    e.Row.Attributes [ onclick] = ClientScript.GetPostBackClientHyperlink ( this .GridView1, 选择


+ e.Row.RowIndex);
}





现在它应该可以正常工作而选择按钮不会显示。


取出所选索引已更改事件并添加Row_Command事件。

如果单击选择按钮,此事件甚至会触发..希望这可以帮助您...





循环遍历javascript的gridview行,找出点击的行(tr)。并为隐藏的按钮发出点击事件..


Hi,

When I use a autogenerated select button in gridview and click on it, the event GridView_selected index changed gets fired.

But I want to fire this event on row click and not on select button click.

How can I Proceed??

解决方案

Please refer my answer - Data GridView selected index changed firing Problem ASP.NET[^].

Update
It seems that without the Select Button, the event is not going to fire. So, do like below.

  1. Make the AutoGenerateSelectButton = "True".
    And write OnSelectedIndexChanged Event.

    AutoGenerateSelectButton="True"
    OnSelectedIndexChanged="GridView1_SelectedIndexChanged"

  2. Add the below Code in RowDataBound Event.

    if (e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.Cells[0].Style.Add(HtmlTextWriterStyle.Display, "none");
    }
    
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Cells[0].Style.Add(HtmlTextWriterStyle.Display, "none");
    
        e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select


" + e.Row.RowIndex); }



Now it should work perfectly and Select button will not show.


Take out "selected index changed" event and add Row_Command event.
this event will even fire if you click "Select" button..hope this helps you..


loop through the gridview rows from javascript and find out the clicked row(tr). and fire a click event for hidden buton..


这篇关于asp.net GridView选择索引已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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