它没有在TabContainer中显示

时间:2014-05-01 18:15:10

标签: c# asp.net gridview

我的代码中有一个ajaxtoolkit:TabContainer。我把gridview放在里面。但是当我运行项目时它没有显示网格视图。 gridview很好,并且当它不在TabContainer中时显示数据。

这是我的aspx代码:

            <ajaxToolkit:TabPanel ID="tbAgency" runat="server" HeaderText="Agency"  >
                   <ContentTemplate>
                       <asp:GridView ID="grAgency" runat="server" CellPadding="4" 
                                                                ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"
                                                                 Width="901px" style="cursor: pointer;" AllowPaging="True" 
                                                                 AllowSorting="True" PageSize="20">
                                                                <AlternatingRowStyle BackColor="White" />
                                                                <EditRowStyle BackColor="#7C6F57" />
                                                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                                                <HeaderStyle BackColor="green" Font-Bold="True" ForeColor="White" 
                                                                    Font-Size="Small" HorizontalAlign="Left" />
                                                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                                                <RowStyle BackColor="#c9d9c9" Font-Size="Small" />
                                                                <SortedAscendingCellStyle BackColor="#F8FAFA" />
                                                                <SortedAscendingHeaderStyle BackColor="#246B61" />
                                                                <SortedDescendingCellStyle BackColor="#D4DFE1" />
                                                                <SortedDescendingHeaderStyle BackColor="#15524A" />
                                                                <Columns>
                                                                    <asp:BoundField HeaderText="Agency Name" DataField="Name" 
                                                                        ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
                                                                    <HeaderStyle HorizontalAlign="Left" />
                                                                        <ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
                                                                    </asp:BoundField>
                                                                    <asp:BoundField HeaderText="Description" DataField="Description" 
                                                                        ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
                                                                    <HeaderStyle HorizontalAlign="Left" />
                                                                        <ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
                                                                    </asp:BoundField>
                                                                    <asp:BoundField HeaderText="Contact Name" DataField="ContactName" 
                                                                        ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
                                                                    <HeaderStyle HorizontalAlign="Left" />
                                                                        <ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
                                                                    </asp:BoundField>
                                                                    <asp:BoundField HeaderText="Contact Phone" DataField="Phone" 
                                                                        ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
                                                                    <HeaderStyle HorizontalAlign="Left" />
                                                                        <ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
                                                                    </asp:BoundField>
                                                                    </Columns>
                                                                </asp:GridView>
                       <asp:Button ID="btnAddAgency" Text="Add Agency" runat="server" />
                       <asp:TextBox ID="txtAgencySearch" runat="server" />
                       <asp:Button ID="btnSearchAgency" runat="server" Text="Search" />
                    </ContentTemplate>    
           </ajaxToolkit:TabPanel>

这是我的C#代码,当下拉列表发生变化时,它会在网格中显示数据。(但是当网格在Tab外部时,只有当我放入Tab中时,网格才会显示。

    protected void ddlPartnerList_SelectedIndexChanged(object sender, EventArgs e)
    {

            Aid = Convert.ToInt32(ddlPartnerList.SelectedItem.Value);
            if (Aid != 0)
            {
            Session["Aid"] = Aid;

            TabContainer1.ActiveTabIndex = 0;


            var AgencyList = adminmv.getAgency(Aid);
            grAgency.DataSource = AgencyList;
            grAgency.DataBind();

        }
    }

1 个答案:

答案 0 :(得分:0)

将GridView放在ContentPamplate内部的TabPanel的ContentTemplate内的UpdatePanel内,并确保页面上有一个ToolkitScriptManager控件。

<tabPanel>
     <contentTemplate>
          <updatePanel>
               <contentTemplate>
                     <gridview>