如何在点击gridview行时停止整页刷新

时间:2013-03-30 07:30:10

标签: asp.net

单击网格视图数据我不希望页面加载完全发生* /

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 + "');");


            }
        }
}

1 个答案:

答案 0 :(得分:1)

ASP.NET Ajax控件允许您进行部分页面更新。您可以将GridView放入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>