0

单击网格视图行时,我不希望重新加载整个页面。下面是被调用的代码。

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


            }
        }
}
4

1 回答 1

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>
于 2013-03-30T07:32:19.897 回答