【问题标题】:command field of grid view in updatepanel didnt work更新面板中 gridview 的命令字段不起作用
【发布时间】:2019-09-04 15:40:30
【问题描述】:

我有一个带有一些命令字段(删除、编辑)的网格视图,它们可以工作,直到我将网格视图放在更新面板中。 它是一个 asp.net 网络表单。 非常感谢...我不习惯使用 asp.net

<h2><%: Title %>Contact List</h2>
<h3>click any contact to edit...</h3>

<asp:Button ID="insert1" runat="server" Height="21px" OnClick="insert1_Click" Text="new contact" />


<div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"  ChildrenAsTriggers="true" UpdateMode="Always">
        <ContentTemplate>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:contact_atidConnectionString %>"
    SelectCommand="SELECT * FROM [contact_list]"
    DeleteCommand="delete from [contact_list] where id=@id"></asp:SqlDataSource>
            <asp:GridView ID="GridView1" runat="server"
                AutoGenerateColumns="False" DataKeyNames="id"
                DataSourceID="SqlDataSource1" Height="30px"
                OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="453px"
                OnRowDeleted="GridView1_RowDeleted" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" EnablePersistedSelection="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
                <AlternatingRowStyle BackColor="#F7F7F7" />
                <Columns>
                    <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" ReadOnly="True" />
                    <asp:BoundField DataField="first name" HeaderText="first name" SortExpression="first name" />
                    <asp:BoundField DataField="last name" HeaderText="last name" SortExpression="last name" />
                    <asp:CommandField ShowDeleteButton="True" />
                    <asp:CommandField ShowSelectButton="True" />
                </Columns>
                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                <SortedAscendingCellStyle BackColor="#F4F4FD" />
                <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
                <SortedDescendingCellStyle BackColor="#D8D8F0" />
                <SortedDescendingHeaderStyle BackColor="#3E3277" />
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

【问题讨论】:

  • 您是否在浏览器开发者工具控制台中看到任何 javascript 错误?您可以按 F12 键启动开发者工具

标签: c# asp.net gridview updatepanel


【解决方案1】:

我发现了我的问题!我只是忘记将逗号按钮必须打开的列表视图放在更新面板中。 这是正确的代码:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
        <ContentTemplate>
            <asp:GridView ID="GridView1" runat="server"
                AutoGenerateColumns="False" DataKeyNames="id"
                DataSourceID="SqlDataSource1" Height="30px"
                OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="453px"
                OnRowDeleted="GridView1_RowDeleted" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" EnablePersistedSelection="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
                CssClass="table table-striped">
                <AlternatingRowStyle BackColor="#F7F7F7" />

                <Columns>
                    <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" ReadOnly="True" />
                    <asp:BoundField DataField="first name" HeaderText="first name" SortExpression="first name" />
                    <asp:BoundField DataField="last name" HeaderText="last name" SortExpression="last name" />
                    <asp:CommandField ShowDeleteButton="True" />
                    <asp:CommandField ShowSelectButton="True" />
                </Columns>
                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                <SortedAscendingCellStyle BackColor="#F4F4FD" />
                <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
                <SortedDescendingCellStyle BackColor="#D8D8F0" />
                <SortedDescendingHeaderStyle BackColor="#3E3277" />
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:contact_atidConnectionString %>"
                SelectCommand="SELECT * FROM [contact_list]"
                DeleteCommand="delete from [contact_list] where id=@id"></asp:SqlDataSource>
            <asp:Panel runat="server">
                <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource2" Visible="true">
                    <ItemTemplate>
                        <tr runat="server">
                            <td>
                                <asp:LinkButton ID="EditButton" runat="Server" Text="SAVE" CommandName="save" OnClick="EditButton_Click" CssClass="btn btn-default btn-lg" BackColor="MediumSpringGreen" />
                            </td>


                            <td>
                                <asp:TextBox ID="TextBox101" runat="Server" Text='<%#Eval("id") %>' Visible="false" class="form-control input-sm" />
                            </td>

                            <td>
                                <asp:TextBox ID="FirstNameLabel" runat="Server" Text='<%#Eval("first name") %>' class="form-control input-sm" />
                            </td>
                            <td>
                                <asp:TextBox ID="LastNameLabel" runat="Server" Text='<%#Eval("last name") %>' class="form-control input-sm" />
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox1" runat="Server" Text='<%#Eval("[street]") %>' class="form-control input-sm" />
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox5" runat="Server" Text='<%#Eval("born date") %>' class="form-control input-sm" />
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox2" runat="Server" Text='<%#Eval("house number") %>' class="form-control input-sm" />
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox3" runat="Server" Text='<%#Eval("telephone") %>' class="form-control input-sm" />
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox4" runat="Server" Text='<%#Eval("pelephone") %>' class="form-control input-sm" />
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:ListView>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>

谢谢你:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多