网格视图即使在绑定后也不可见

本文关键字:绑定 视图 网格 | 更新日期: 2023-09-27 17:57:11

我陷入了一些奇怪的情况,我在ajax工具包选项卡容器中有一个网格视图。在选项卡索引更改上,我正在绑定网格。但什么也没发生。网格未显示。我检查了以下内容

  1. 视图状态
  2. 网格的可见性
  3. 父表的可见性。
  4. 数据来自方法
  5. 选项卡面板的可见性

即使我已经调试并添加了监视以在加载页面之前检查它是否为空。

请帮帮我

**以下是

更新的代码**

    <HTMLCode>
     <Toolkit:TabPanel HeaderText="Pending Challans" ID="tpPendingChallan" runat="server" Height="200px" >
     <ContentTemplate>
      <table style="width: 100%">
        <tr>
          <td>
            <asp:GridView ID="gvPendingChallans"  runat="server" AutoGenerateColumns="True"  CellPadding="4" Width="100%"  OnPageIndexChanging="gvPendingChallans_PageIndexChanging" 
        OnRowCommand="gvPendingChallans_RowCommand" AllowPaging="True"  GridLines="None">
            </asp:GridView>
            </td>
          </tr>
         </table>
    </ContentTemplate>
  </Toolkit:TabPanel>
    </HTMLCode>

====

============================================================================
 <C#>
      private void BindPendingChallans()
            {
                var dat = JobCardManager.DisplayChallan();
                gvPendingChallans.DataSource = dat;
                gvPendingChallans.DataBind();
            }
     protected void tcMembers_ActiveTabChanged(object sender, EventArgs e)
    {
        if(tcMembers.ActiveTabIndex == 6)
        {
            BindPendingChallans();
        }
    }
    </C#>

网格视图即使在绑定后也不可见

很抱歉错过了我的第一个答案对您的代码的解释。 我以为这只是一个简单的网格视图填充,但作为审查,我发现您正在使用 Ajax Toolkit 库,并且您的网格位于选项卡选择内。 你可以试试这个:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="Toolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            font-family: Arial;
            color: #3399FF;
        }
    </style>
</head>
<body class="style1">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager2" runat="server" EnablePageMethods="true" />
    <div>
        <asp:UpdatePanel ID="upMember" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <table cellpadding="1" cellspacing="4" border="0" width="100%">
                    <tr>
                        <td>
                            <Toolkit:TabContainer ID="tcMembers" runat="server" AutoPostBack="true" 
                                ActiveTabIndex="0" onactivetabchanged="tcMembers_ActiveTabChanged">
                                <Toolkit:TabPanel HeaderText="Pending Challans" ID="tpPendingChallan" runat="server"
                                    Height="200px">
                                      <ContentTemplate>
                                        <asp:GridView ID="gvPendingChallans" runat="server" AutoGenerateColumns="True" CellPadding="4"
                                            Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging" OnRowCommand="gvPendingChallans_RowCommand"
                                            AllowPaging="True" GridLines="None">
                                        </asp:GridView>
                                    </ContentTemplate>
                                </Toolkit:TabPanel>
                                 <Toolkit:TabPanel HeaderText="Pending 2" ID="tpPending2" runat="server"
                                    Height="200px">
                                       <ContentTemplate>
                                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" CellPadding="4"
                                            Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging" OnRowCommand="gvPendingChallans_RowCommand"
                                            AllowPaging="True" GridLines="None">
                                        </asp:GridView>
                                    </ContentTemplate>
                                </Toolkit:TabPanel>
                            </Toolkit:TabContainer>
                        </td>
                        <td width="2%">
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

然后在您的代码隐藏中:

protected void Page_Load(object sender, EventArgs e)
    {
        upMember.Update();
    }
    private void BindPendingChallans()
    {
        //var dat = JobCardManager.DisplayChallan(); 
        //gvPendingChallans.DataSource = dat; gvPendingChallans.DataBind(); 
    }
    protected void tcMembers_ActiveTabChanged(object sender, EventArgs e)
    {
        if (tcMembers.ActiveTabIndex == 6)
        {
            BindPendingChallans();
        }
    }
    protected void gvPendingChallans_PageIndexChanging(object sender, GridViewPageEventArgs e){
    }
    protected void gvPendingChallans_RowCommand(object sender, GridViewCommandEventArgs e){
    }

注意:在"tcMembers_ActiveTabChanged"中,您指定了选项卡索引6 选项卡索引以 0 开头。 也许你可以根据数量进行调整 你打算的标签....

问候