2012-10-30 127 views
0

i'have創建了一個gridview並啓用編輯模式,但是當我點擊每行上的「編輯」鏈接,沒有發生任何事情,並保持當前狀態,這裏是代碼新聞編輯鏈接沒有發生在gridview編輯模式

<form id="form1" runat="server"> 
<div> 

    <asp:GridView 
     ID="GridView1" runat="server" AllowPaging="True" 
     AutoGenerateColumns="False" CellPadding="4" DataKeyNames="id" 
     DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" 
     AllowSorting="True" PageSize="50" style="text-align: center" Width="100%" OnRowDataBound="GridView1_RowDataBound"> 
     <AlternatingRowStyle BackColor="White" /> 
     <Columns> 
      <asp:CommandField ShowEditButton="True" /> 
      <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" /> 
      <asp:TemplateField HeaderText="full_content" SortExpression="full_content"> 
       <EditItemTemplate> 
        <asp:TextBox ID="TextBox1" runat="server" 
         Text='<%# Bind("full_content", "{0}") %>'></asp:TextBox> 
       </EditItemTemplate> 
       <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("full_content") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:BoundField DataField="filename" HeaderText="filename" 
       SortExpression="filename" /> 
      <asp:BoundField DataField="confidential" HeaderText="confidential" 
       SortExpression="confidential" /> 
      <asp:BoundField DataField="nid" HeaderText="nid" SortExpression="nid" /> 
     </Columns> 
     <EditRowStyle BackColor="#2461BF" /> 
     <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> 
     <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> 
     <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> 
     <RowStyle BackColor="#EFF3FB" /> 
     <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" 
      HorizontalAlign="Left" /> 
     <SortedAscendingCellStyle BackColor="#F5F7FB" /> 
     <SortedAscendingHeaderStyle BackColor="#6D95E1" /> 
     <SortedDescendingCellStyle BackColor="#E9EBEF" /> 
     <SortedDescendingHeaderStyle BackColor="#4870BE" /> 
    </asp:GridView> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:earchConnectionString %>" 
     SelectCommand="SELECT * FROM [full_content] WHERE ([nid] = @nid)" 
     DeleteCommand="DELETE FROM [full_content] WHERE [id] = @original_id" 
     InsertCommand="INSERT INTO [full_content] ([title], [full_content], [filename], [confidential], [nid]) VALUES (@title, @full_content, @filename, @confidential, @nid)" 
     OldValuesParameterFormatString="original_{0}" 
     UpdateCommand="UPDATE [full_content] SET [title] = @title, [full_content] = @full_content, [filename] = @filename, [confidential] = @confidential, [nid] = @nid WHERE [id] = @original_id"> 
     <DeleteParameters> 
      <asp:Parameter Name="original_id" Type="Int32" /> 
     </DeleteParameters> 
     <InsertParameters> 
      <asp:Parameter Name="title" Type="String" /> 
      <asp:Parameter Name="full_content" Type="String" /> 
      <asp:Parameter Name="filename" Type="String" /> 
      <asp:Parameter Name="confidential" Type="Byte" /> 
      <asp:Parameter Name="nid" Type="Int32" /> 
     </InsertParameters> 
     <SelectParameters> 
      <asp:QueryStringParameter DefaultValue="1" Name="nid" QueryStringField="id" 
       Type="Int32" /> 
     </SelectParameters> 
     <UpdateParameters> 
      <asp:Parameter Name="title" Type="String" /> 
      <asp:Parameter Name="full_content" Type="String" /> 
      <asp:Parameter Name="filename" Type="String" /> 
      <asp:Parameter Name="confidential" Type="Byte" /> 
      <asp:Parameter Name="nid" Type="Int32" /> 
      <asp:Parameter Name="original_id" Type="Int32" /> 
     </UpdateParameters> 
    </asp:SqlDataSource> 

</div> 
</form> 

任何人都知道問題在哪裏?感謝

回答

0

添加row editting event爲foloow ....

<asp:GridView 
     ID="GridView1" runat="server" AllowPaging="True" 
     AutoGenerateColumns="False" CellPadding="4" DataKeyNames="id" 
     DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" 
     AllowSorting="True" PageSize="50" style="text-align: center" Width="100%" OnRowDataBound="GridView1_RowDataBound" 
     OnRowEditing="GridView1_RowEditing"> 

寫下RowEditing事件下面的代碼....

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) 
    { 
    //Set the edit index. 
    GridView1.EditIndex = e.NewEditIndex; 
    //Bind data to the GridView control. 
    BindData(); 
    } 

你可以得到關於此Row Editing

行編輯更多的數據