简体   繁体   English

即使绑定后,GridView也不可见

[英]Gridview not visible even after binding

I got stucked to some weird condition where I have a gridview inside a ajax toolkit tabcontainer. 我陷入了某种奇怪的状况,即我在ajax工具包tabcontainer内有一个gridview。 On tab index change i am binding grid. 在选项卡索引更改上,我绑定网格。 But nothing happend. 但是什么也没发生。 Grid is not appearing. 网格未出现。 I have check the following 我检查了以下内容

  1. Viewstate 观看状态
  2. Visibility of grid 网格的可见性
  3. Visibility of the parent table. 父表的可见性。
  4. Data is coming from the method 数据来自方法
  5. visibility of the tab panel 标签面板的可见性

Even i have debugged and added watch to check if its getting null before loading the page. 甚至我已经调试并添加了watch,以在加载页面之前检查其是否为null。

Please help me out 请帮帮我

** BELOW IS THE UPDATED CODE** **下面是更新的代码**

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

Sorry for miss interpretation of your code with my first answer. 抱歉,我的第一个答案未解释您的代码。 I thought that it just a simple population of grid view, but as review I found that you are using the Ajax Toolkit library and your grid is inside the tab selection. 我认为这只是网格视图的简单填充,但是经过审查,我发现您正在使用Ajax Toolkit库,并且网格位于选项卡中。 You can try this: 您可以尝试以下方法:

<%@ 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>

Then in your code behind: 然后在您的代码后面:

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){
    }

Note: That in you 'tcMembers_ActiveTabChanged' you had specify tab index 6 The Tab index begins with 0. Maybe you can adjust it depending the number of you Intended tab.... 注意:在您的“ tcMembers_ActiveTabChanged”中,您指定了标签索引6标签索引以0开头。也许您可以根据要使用的标签的数量对其进行调整。...

Regards, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM