日期:2014-05-18  浏览次数:20456 次

为什么加上if (!IsPostBack) ,Gridview就不會調用 GridView1_RowEditing方法 了,如果去除就可以
下面是代码:


 <asp:GridView ID="gviewEditDel" runat="server" AutoGenerateColumns="False" Width="400px" AllowPaging="True" 
OnRowCancelingEdit="gviewEditDel_RowCancelingEdit" 
OnRowDeleting="gviewEditDel_RowDeleting" 
OnRowEditing="gviewEditDel_RowEditing" 
OnRowUpdating="gviewEditDel_RowUpdating"
 PageSize="5" >
  <Columns>  
  <asp:TemplateField HeaderText="好友描述" SortExpression="FriendDesc">
  <HeaderStyle Width="600px"/>
  <EditItemTemplate>
  <asp:TextBox ID="FriendDesc" runat="server" Text='<%# Bind("FriendDesc") %>'></asp:TextBox>
  </EditItemTemplate>
  <ItemTemplate>
  <asp:Label ID="FriendDesc" runat="server" Text='<%# Bind("FriendDesc") %>'></asp:Label>
  </ItemTemplate>
  </asp:TemplateField>
   
  <asp:TemplateField HeaderText="编辑好友" ShowHeader="False">
  <HeaderStyle Width=200px/>
  <EditItemTemplate>
  <asp:LinkButton ID="Update" runat="server" CausesValidation="True" CommandName="Update"
  Text="更新"></asp:LinkButton>
  <asp:LinkButton ID="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"
  Text="取消"></asp:LinkButton>
  </EditItemTemplate>
  <ItemTemplate>
  <asp:LinkButton ID="Edit" runat="server" CausesValidation="False" CommandName="Edit"
  Text="编辑"></asp:LinkButton>
  </ItemTemplate>
  </asp:TemplateField>
  <asp:TemplateField HeaderText="删除好友" ShowHeader="False">
  <HeaderStyle Width="150px" Font-Size=14pt />
  <ItemTemplate>
  <asp:LinkButton ID="Delete" runat="server" CausesValidation="False" CommandName="Delete"
  Text="删除"></asp:LinkButton>
  </ItemTemplate>
  </asp:TemplateField>
  </Columns>  
   
  </asp:GridView>





cs中是:

  protected void Page_Load(object sender, EventArgs e)