1

我会感谢你的帮助。我正在尝试向我的页面添加一个更新面板,因此它只刷新网格视图而不是漏洞页面。我必须将它插入不同的地方,但它似乎不起作用,仍然刷新了孔页面。我应该在哪里插入它?

我有一个下拉列表,通过它填充网格视图。这是代码:

 <%@ Page Title="All Products" Language="C#" MasterPageFile="~/MasterPage/MasterPage.master" AutoEventWireup="true" CodeFile="All.aspx.cs" Inherits="Catalog_All" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style4
        {
            width: 100%;
        }
        .style5
        {
            width: 620px;
        }
        .style6
        {
            font-size: large;
            text-decoration: underline;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>

  <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
                    AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="CategoryName" 
                    DataValueField="categoryId" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem Value="">choose pet</asp:ListItem>
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:AllPets %>" 
                    SelectCommand="SelectAllCategories" SelectCommandType="StoredProcedure">
                </asp:SqlDataSource>





    <table class="style4">
        <tr>
            <td colspan="2" class="style6">
                <strong>All products</strong></td>
        </tr>

        <tr>
            <td class="style5">
                &nbsp;</td>
            <td>

            </td>
        </tr>
        <tr>

            <td class="style5">

                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                    DataKeyNames="ProductID" DataSourceID="SqlDataSource1" AllowPaging="True">


                    <Columns>
                        <asp:BoundField DataField="ProductName" HeaderText="product" 
                            SortExpression="ProductName" />
                        <asp:ImageField DataAlternateTextField="picPath" DataImageUrlField="picPath" 
                            HeaderText="pic">
        </asp:ImageField>
                        <asp:BoundField DataField="Price" HeaderText="price" 
                            SortExpression="Price" />
                        <asp:BoundField DataField="Summary" HeaderText="des" 
                            SortExpression="Summary" />
                    </Columns>

                </asp:GridView>

                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:get_products_bypet %>" 
                    SelectCommand="get_products_bypet" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="DropDownList1" Name="categoryId" 
                            PropertyName="SelectedValue" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>


            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style5">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style5">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>


</div>

</asp:Content>

tahnx 的帮助

4

2 回答 2

1

将其添加到 Content 标记之后,直到最后,因为您使用 DropDownList 进行自动完整回发

    <asp:Content ID="Content2" ..>
        <asp:UpdatePanel ID="updPanl" runat="server" RenderMode="Block" UpdateMode="Conditional" >
        <ContentTemplate>
       ........ rest code .........
        </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Content>
于 2012-10-06T15:18:33.583 回答
0

试试这个,把下拉列表和gridview放在同一个更新面板中。如果您不想将下拉菜单放在同一个面板中,请检查第二个答案

<asp:UpdatePanel runat="server" ID="Upd">
<ContentTemplate>

      <%-- Dropdown list here should work --%>

      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="ProductID" DataSourceID="SqlDataSource1" AllowPaging="True">


                <Columns>
                  ....
                </Columns>

            </asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

如果您不想将下拉菜单放在同一个更新面板中,请使用触发器

<%-- dropdown list outside here --%>
<asp:UpdatePanel runat="server" ID="Upd">
 <ContentTemplate>
       <%-- Only your Gridview here --%>
 </ContentTemplate>

 <Triggers>
 <asp:AsyncPostBackTrigger ControlID="DropdownList1" 
     EventName="SelectedIndexChange" />
 </Triggers>
 </asp:UpdatePanel>
于 2012-10-06T15:19:09.390 回答