如何阻止整个页面刷新的GridView的行点击 [英] how to stop whole page refresh on click of gridview row

查看:139
本文介绍了如何阻止整个页面刷新的GridView的行点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在点击网格视图的数据,我不希望它是页面加载发生compleatly * /

 保护无效GridView1_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
    尝试
    {
        如果(e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes [的onmouseover] = \"this.style.cursor='pointer';this.style.textdecoration='underline';this.style.background='#DDDDDD';\";
            如果((e.Row.RowIndex%2)== 0)//如果连排
                 e.Row.Attributes [的onmouseout] =this.style.textdecoration =无; this.style.cursor ='指针'; this.style.background ='#EFF3FB';;
            其他
                 e.Row.Attributes [的onmouseout] =this.style.textdecoration =无; this.style.cursor ='指针'; this.style.background ='白';;
              e.Row.Attributes.Add(onclick事件,使用Javascript:__ doPostBack('MyClick认证','+ e.Row.RowIndex +'););
            }
        }
}


解决方案

在ASP.NET Ajax控件让你做局部页面更新。你可以把GridView控件到的UpdatePanel

 < ASP:的UpdatePanel ID =myUpdatePanel=服务器的UpdateMode =条件ChildrenAsTriggers =false的>
    <&的ContentTemplate GT;
 < ASP:GridView控件ID =CustomersGridView
   的DataSourceID =CustomersSource
   的AutoGenerateColumns =FALSE
   autogenerateselectbutton =真
   allowpaging =真
   的selectedIndex =1
   onselectedindexchanged =CustomersGridView_SelectedIndexChanged
   onselectedindexchanging =CustomersGridView_SelectedIndexChanging
   =服务器的DataKeyNames =客户ID>     <柱体和GT;
         < ASP:BoundField的数据字段=客户ID
             的HeaderText =客户ID
             InsertVisible =FALSE只读=真
             SORTEX pression =客户ID/>
         < ASP:BoundField的数据字段=姓
             的HeaderText =姓
             SORTEX pression =名字/>
         < ASP:BoundField的数据字段=中间名
             的HeaderText =中间名
             SORTEX pression =中间名/>
         < ASP:BoundField的数据字段=姓氏
             的HeaderText =姓氏
             SORTEX pression =姓氏/>
         < ASP:BoundField的数据字段=手机
             的HeaderText =手机
             SORTEX pression =电话/>
     < /专栏>   < selectedrowstyle背景色=浅青绿
     前景色=DarkBlue
     字体加粗=真/> < / ASP:GridView的>
     < /&的ContentTemplate GT;
     <&触发器GT;
         < ASP:PostBackTrigger控件ID =CustomersGridView事件名称=的SelectedIndexChanged/>
     < /触发器>
< / ASP:的UpdatePanel>

on Click Grid View Data i don't want it to be Page load happens compleatly */

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    try
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textdecoration='underline';this.style.background='#DDDDDD';";
            if ((e.Row.RowIndex % 2) == 0)  // if even row
                 e.Row.Attributes["onmouseout"] = "this.style.textdecoration='none';this.style.cursor='pointer';this.style.background='#EFF3FB';";
            else  
                 e.Row.Attributes["onmouseout"] = "this.style.textdecoration='none';this.style.cursor='pointer';this.style.background='White';";
              e.Row.Attributes.Add("onclick", "Javascript:__doPostBack('myClick','" + e.Row.RowIndex + "');");


            }
        }
}

解决方案

The ASP.NET Ajax controls let you do partial page updates. You can put the GridView into an UpdatePanel.

<asp:UpdatePanel ID="myUpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
 <asp:gridview id="CustomersGridView" 
   datasourceid="CustomersSource" 
   autogeneratecolumns="False"
   autogenerateselectbutton="True"
   allowpaging="True" 
   selectedindex="1"
   onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
   onselectedindexchanging="CustomersGridView_SelectedIndexChanging"   
   runat="server" DataKeyNames="CustomerID">

     <Columns>
         <asp:BoundField DataField="CustomerID" 
             HeaderText="CustomerID" 
             InsertVisible="False" ReadOnly="True" 
             SortExpression="CustomerID" />
         <asp:BoundField DataField="FirstName" 
             HeaderText="FirstName" 
             SortExpression="FirstName" />
         <asp:BoundField DataField="MiddleName" 
             HeaderText="MiddleName" 
             SortExpression="MiddleName" />
         <asp:BoundField DataField="LastName" 
             HeaderText="LastName" 
             SortExpression="LastName" />
         <asp:BoundField DataField="Phone" 
             HeaderText="Phone" 
             SortExpression="Phone" />
     </Columns>

   <selectedrowstyle backcolor="LightCyan"
     forecolor="DarkBlue"
     font-bold="true"/>  

 </asp:gridview>
     </ContentTemplate>
     <Triggers>
         <asp:PostBackTrigger ControlID="CustomersGridView" EventName="SelectedIndexChanged" />
     </Triggers>
</asp:UpdatePanel>

这篇关于如何阻止整个页面刷新的GridView的行点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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