0

我已经创建了一个网格视图并启用了编辑模式,但是当我单击每一行上的“编辑”链接时,没有发生任何事情并保持当前状态,这里是代码

<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>

有谁知道问题出在哪里?谢谢

4

1 回答 1

0

添加row editting event为以下...

<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();
  }

您可以在此处获取有关行编辑的更多数据行编辑

于 2012-10-30T06:15:49.263 回答