这个是页面代码:
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
   </asp:GridView>      
这个是cs代码:            WorkFlowCommon wCommon = new WorkFlowCommon();
            DataTable dt = wCommon.GetWorkFlowList(" and fd_seq=0");
            GridView1.DataSource = dt;
            GridView1.DataBind();看上去好像没错啊~为什么取不到数据啊?

解决方案 »

  1.   

    看看你的方法返回的DataTable里面有没有结果
      

  2.   

    调试看你 DataTable dt = wCommon.GetWorkFlowList(" and fd_seq=0");
    dt里估计没数据的
      

  3.   

    WorkFlowCommon wCommon = new WorkFlowCommon();
    DataTable dt = wCommon.GetWorkFlowList(" and fd_seq=0");
    if(dt.Rows.Count == 0)
    {
     Response.Write("没有数据你绑定啥啊");
    }
    else
    {
      GridView1.DataSource = dt;
      GridView1.DataBind();
    }
      

  4.   

    这部分:
    WorkFlowCommon wCommon = new WorkFlowCommon();
      DataTable dt = wCommon.GetWorkFlowList(" and fd_seq=0");
      GridView1.DataSource = dt;
      GridView1.DataBind();放在哪里,Page_load?
      

  5.   

    我把代码全贴上来算了~<asp:UpdatePanel ID="UpdatePanel1" runat="server"  UpdateMode="Conditional">
                                    <ContentTemplate>
                                        <asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick">
                                        </asp:Timer>
                                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
                                        </asp:GridView>    
       <asp:Panel ID="dxtx" runat="server" Visible="false">
                                                        <bgsound src='./dxtx.wav' />
                                         </asp:Panel>  
                                    </ContentTemplate>
                                </asp:UpdatePanel>   protected void Timer1_Tick(object sender, EventArgs e)
        {
            //如果有待办事宜,就播放声音        
            try
            {            WorkFlowCommon wCommon = new WorkFlowCommon();
                DataTable dt = wCommon.GetWorkFlowList(" and fd_seq=0");
                GridView1.DataSource = dt;
                GridView1.DataBind();            dt = null;            DateTime freshTime = DateTime.Now;            int count = wCommon.GetNewWaitMattersCount(EmpSeq, DeptNo, freshTime,FreshTimeSpan);
                if (count > 0)
                    dxtx.Visible = true;
                else
                    dxtx.Visible = false;
                //dxtx.Visible = true;            wCommon = null;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }    }
      

  6.   

    dt = null;把这个去掉看看先
      

  7.   

    先看下你的datatable里返回值有没有数据   有接下来的才有意义,要不分析半天都是白费
      

  8.   

    DataTable dt = wCommon.GetWorkFlowList(" and fd_seq=0");
    快速监视下dt。
    应该是没有数据的.
      

  9.   

    你在GridView1.DataBind(); 这个加一个断点 看下能不能绑定到GridView1上去 
      

  10.   

    Interval="10000"这段时间过后才触发timer事件并显示数据绑定,要想直接运行显示绑定你在load里面绑定。
      

  11.   

    监视这个GridView1.DataSet,看看是什么时候数据消失的
      

  12.   

    一直到GridView1.DataBind()都没消失
    还有这些我都是放在表格的一个单元格中的
      

  13.   

    你这样写能找到 GridView1 这个控件吗?你应该这样写,GridView1 gv1 = UpdatePanel1.ContentTemplate.findControl('GridView1') as GridView; 然后gv1.DataSource=dt; gv1.DataBind();
      

  14.   

    你的数据10秒之内能加载完么?
    加个UpdateProgress看看状态                                    <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                                         <ProgressTemplate>
                                         等待
                                         </ProgressTemplate>
                                         </asp:UpdateProgress>
      

  15.   

    除了楼上说的之外,还有一种可能: 楼主可能给GridView1添加了一些columns,但是没有给它的columns的 FieldName 或 DataField 赋值,与你的 sql查询时的 fieldName一致即可
      

  16.   

    AutoGenerateColumns="true" 这个属性去掉试试看。