Gridview列跨度不起作用 [英] Gridview column span not working

查看:96
本文介绍了Gridview列跨度不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有gridview从sql server获取数据表。当数据表没有行时,我已经编写了一个函数来绑定gridview来自一个单独的源,它将一个新行添加到gridview,同时合并所有列并显示错误消息找不到结果但这不起作用所有列都显示原样。下面给出了绑定空网格的功能



I have gridview which takes datatable from sql server. When the datatable has no rows i have written a funtion to bind the gridview from a seperate source which adding a new row to the gridview also merging all columns and displaying error messeage"No Result found" but this is not working the all columns are displaying as it is. The function for binding empty grid is given below

private void ShowNoResultFound(DataTable source, GridView gv, bool footerStatus)
       {
           source.Rows.Add(source.NewRow());
           gv.DataSource = source;

           gv.ShowFooter = footerStatus;

           int columnsCount = gv.Columns.Count;
           gv.DataBind();
           gv.Rows[0].Cells.Clear();
           gv.Rows[0].Cells.Add(new TableCell());
           gv.Rows[0].Cells[0].ColumnSpan = columnsCount;


           gv.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
           gv.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red;
           gv.Rows[0].Cells[0].Font.Bold = true;

           gv.Rows[0].Cells[0].Text = "NO RESULT FOUND!";

       }

推荐答案

请使用网格视图RowDataBound事件。我刚刚测试过。你可以参考下面的代码,但你需要在RowDataBound中使用一些标志,这样只有当你有空数据时它才会被执行。



Please use grid view RowDataBound event. I just tested. You can refer below code but you need to use some flag in RowDataBound so that it get executed only when you have empty data.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {

          if (e.Row.RowType == DataControlRowType.DataRow)
          {   var columnsCount = e.Row.Cells.Count;
              e.Row.Cells.Clear();
              var tc = new TableCell();
              tc.Text = "Empty";
              tc.ColumnSpan = columnsCount;
              e.Row.Cells.Add(tc);
          }
      }


这篇关于Gridview列跨度不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆