即使绑定后Gridview也不可见

时间:2011-05-23 07:33:39

标签: c# asp.net gridview

我遇到了一些奇怪的情况,我在ajax工具包tabcontainer中有一个gridview。在选项卡索引更改我绑定网格。但没有任何事情发生。网格没有出现。我检查了以下内容

  1. 视图状态
  2. 网格的可见性
  3. 父表的可见性。
  4. 数据来自方法
  5. 标签面板的可见性
  6. 即使我已经调试并添加了watch来检查它是否在加载页面之前变为null。

    请帮帮我

    **以下是更新的代码**

        <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#>
    

1 个答案:

答案 0 :(得分:0)

很抱歉我的第一个答案错过了对您的代码的解释。我认为它只是一个简单的网格视图,但是作为评论,我发现您使用的是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){
    }

注意:您在'tMeMembers_ActiveTabChanged'中指定了标签索引6       Tab索引从0开始。也许您可以根据数量调整它       你是预期的标签......

此致