【问题标题】:datagrid it is not showing in TabContainer数据网格未显示在 TabContainer 中
【发布时间】:2014-05-01 18:15:09
【问题描述】:

我的代码中有一个 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# 代码,当下拉列表更改时,它会在网格中显示数据。(但网格仅在选项卡外部时可见,当我放入选项卡时消失。

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

        }
    }

【问题讨论】:

  • 如果你删除了gridview并在你的标签中放置了一些文本,文本是否正确显示?
  • @RickS 是的,它显示文本。
  • 您的 Page_Load 中有什么内容?您在那里与 grAgency 合作吗?
  • @RickS 不,我在页面加载中没有任何与 grAgency 相关的内容

标签: c# asp.net gridview


【解决方案1】:

将 GridView 放入 TabPanel 的 ContentTemplate 内的 UpdatePanel 内的 ContentTemplate 中,并确保页面上有 ToolkitScriptManager 控件。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多