2013-03-30 41 views
0

的点击整页刷新,我不希望它是页面加载发生compleatly */如何停止上点击网格视图数据的GridView列

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

的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> 
+0

我用阿贾克斯,但它不工作.. –

+0

它怎么不工作?你是否正确地连接了PostBackTrigger? –

+0

但我更新面板的触发器的属性 –

相关问题