如何添加网格视图以更新面板

时间:2014-03-14 08:38:29

标签: gridview updatepanel asp.net-3.5

我只想添加网格视图来更新面板以进行快速排序和Pagging请求。我的网格视图工作正常。在这里我只想添加一个触发器,如一个链接按钮,但它给我运行时错误如:

A control with ID 'lbut_category' i set as AsyncPostBackTrigger

这是我的设计视图:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
           <asp:GridView ID="GV_ViewCategories" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
            GridLines="None" Width="100%" 
            ondatabound="GV_ViewCategories_DataBound" 
            onpageindexchanging="GV_ViewCategories_PageIndexChanging" 
            onprerender="GV_ViewCategories_PreRender" 
            onrowcommand="GV_ViewCategories_RowCommand" 
            onrowdatabound="GV_ViewCategories_RowDataBound" 
            onsorting="GV_ViewCategories_Sorting" DataKeyNames="Id">
            <RowStyle CssClass="grid1" HorizontalAlign="Left" />
            <Columns>
                <asp:TemplateField>
                    <HeaderStyle CssClass="headinglist_bg" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Category Name" SortExpression="CategoryName">
                    <HeaderStyle CssClass="headinglist_bg" />
                    <ItemTemplate>
                        <asp:LinkButton ID="lbut_category" runat="server" 
                            CommandArgument='<%# Eval("Id") %>' CommandName="View" 
                            Text='<%# Bind("CategoryName") %>'></asp:LinkButton>
                    </ItemTemplate>
                    <HeaderTemplate>
                        <asp:LinkButton ID="lbut_sortname" runat="server" 
                            CommandArgument="CategoryName" CommandName="Sort" CssClass="normaltext" 
                            Font-Bold="true" Text="Category Name"></asp:LinkButton>
                        <asp:PlaceHolder ID="placeholdercategory" runat="server"></asp:PlaceHolder>
                    </HeaderTemplate>
                    <ItemStyle CssClass="quicklink" />
                </asp:TemplateField>
            </Columns>
            <EmptyDataRowStyle BorderWidth="0px" Width="0px" />
            <EmptyDataTemplate>
                <asp:Label ID="Label2" runat="server" ForeColor="Red" 
                    Text="No Records are found"></asp:Label>
            </EmptyDataTemplate>
            <PagerStyle CssClass="pager" HorizontalAlign="Center" VerticalAlign="Middle" />
            <PagerTemplate>
                <table>
                    <tr>
                        <td>
                            <asp:ImageButton ID="ImageButton1" runat="server" 
                                AlternateText="Go to First Page" CommandArgument="First" CommandName="Page" 
                                ImageUrl="../images/1330128819_resultset_first.png" />
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton2" runat="server" AlternateText="Previous Page" 
                                CommandArgument="Prev" CommandName="Page" 
                                ImageUrl="../images/1330128981_resultset_previous.png" />
                        </td>
                        <td>
                            Page&nbsp;<asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True" 
                                OnSelectedIndexChanged="ddlPages_SelectedIndexChanged">
                            </asp:DropDownList>
                            of
                            <asp:Label ID="lblPageCount" runat="server"></asp:Label>
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton3" runat="server" AlternateText="Next Page" 
                                CommandArgument="Next" CommandName="Page" 
                                ImageUrl="../images/Farm-Fresh_resultset_next.png" />
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton4" runat="server" 
                                AlternateText="Go to Last Page" CommandArgument="Last" CommandName="Page" 
                                ImageUrl="../images/1330128876_resultset_last.png" />
                        </td>
                    </tr>
                </table>
            </PagerTemplate>
            <FooterStyle CssClass="pager" VerticalAlign="Bottom" />
            <HeaderStyle HorizontalAlign="Left" />
        </asp:GridView>
        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="GV_ViewCategories" 
                    EventName="RowCommand" />
            </Triggers>
        </asp:UpdatePanel>

并且为了解决无效回调和回发参数我设置了EnableEventValidation="false"但是在这里我必须双击链接按钮然后它才会响应。

这里EnableEventValidation="false"出于安全考虑可能会有危险。

任何机构都能解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

设置ChildrenAsTriggers =“true”就足以触发updatepanel的回发。在这种情况下,您不需要添加PostBackTrigger。无法找到lbut_sort_person_name,因为它位于不同的命名容器中,即gridview控件的一行。