如何通过从表中检索数据来绑定网格列? [英] How to bind grid columns by retrieving data from a table?

查看:56
本文介绍了如何通过从表中检索数据来绑定网格列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过从表中检索数据来绑定网格列标题名称。这个表有两个字段,ID和ExpenseName,我想将ExpenseNames显示为Grid的Column标题。实际上我正在创建人员网格视图。我希望工作人员的所有费用名称都显示为标题。



请给我一些想法。



提前致谢。

解决方案

 DataTable dt = GetTable(); 
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Columns [ 0 ]。HeaderText = dt.Columns [ 0 ]。ColumnName;


您好,



请按以下方式绑定您的网格。



 DataSet ds = GetExpenseName(); 
if (ds!= null&& ds.Table [ 0 ]。行。 count> 0)
{
for int i = 0 ; i< ds.table [ 0 ]。rows.count; i ++)>
{
GridViewName.Column [i] .HeaderText = ds.Table [ 0 ]。Row [i] [ ExpenseNames]。ToString();
}
}



希望这会对你有帮助。


  protected   void  gvSearchResult_RowDataBound( object  sender,GridViewRowEventArgs e)
{

尝试
{
if (e.Row.RowType == DataControlRowType.Header)
{
Label lblSearchResults =(Label)e.Row.FindControl( lblSearchResults);
lblSearchResults.Text =((DataRowView)e.Row.DataItem)[ 列名]的ToString();
}
}
}







这可能适用于你


I want to bind my grid column header names by retrieving data from a table. This table has two fields,ID and ExpenseName, I want to display the ExpenseNames as Column header of the Grid. Actually I am creating Staff grid view. I want all the Expense names of staff to be displayed as a header.

Please Give me some ideas.

Thanks in advance.

解决方案

DataTable dt = GetTable();
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Columns[0].HeaderText = dt.Columns[0].ColumnName;


Hi,

Please bind your grid as below.

DataSet ds = GetExpenseName();
if(ds!=null&&ds.Table[0].Rows.count>0)
{
  for(int i=0;i<ds.table[0].rows.count;i++)>
  {
    GridViewName.Column[i].HeaderText = ds.Table[0].Row[i]["ExpenseNames"].ToString();
  }
}


Hope this will help you.


protected void gvSearchResult_RowDataBound(object sender, GridViewRowEventArgs e)
  {

    try
     {
        if (e.Row.RowType == DataControlRowType.Header)
          {
              Label lblSearchResults =            (Label)e.Row.FindControl("lblSearchResults");
              lblSearchResults.Text = ((DataRowView)e.Row.DataItem)["Column Name"].ToString();
          }
     }
}




This might work for you


这篇关于如何通过从表中检索数据来绑定网格列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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