如何仅在gridview中显示选定的列,其中gridview列元素在运行时创建 [英] How do I display only selected column in gridview where gridview column element is created at runtime

查看:51
本文介绍了如何仅在gridview中显示选定的列,其中gridview列元素在运行时创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请代码如下所示:



public NameList [] NavisionJobList(string UserID)

{

//逻辑

//返回特定值

}



和我的aspx页面,将返回值绑定到网格的代码是:



Grid.DataSource = fetchnavisionData.NavisionJobList(Ramesh);

Grid.DataBind();



在客户端,gridview的代码是:

 <   asp:GridView     ID   = 网格 < span class =code-attribute>   runat   =  server >  
< / asp:GridView >





使用这个,我按照预期将所有字段作为gridview中的列。但是我只希望选择的字段显示在网格而不是所有字段中。我怎么能这样做。???

在客户端,我添加了绑定字段,但这导致重复网格中的列< columns> 。帮我解决问题..

解决方案

  protected   void  GridView1_RowDataBound( object  sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 此处应用您的条件
if (Request.QueryString [ name] == all
e.Row.Cells [< index_of_cell>]。Visible = true ;
else
e.Row.Cells [< index_of_cell>]。Visible = false ;
}
}


我添加了autogeneratedcolumn并将其设置为true并手动添加了列字段和属性,它工作,。,

The code of my application is shown below:

public NameList[] NavisionJobList(string UserID)
{
//logic
// return certain value
}

and in my aspx page, the code to bind the returned value to grid is:

Grid.DataSource = fetchnavisionData.NavisionJobList("Ramesh");
Grid.DataBind();

In client side the code of gridview is:

<asp:GridView ID="Grid" runat="server">
          </asp:GridView>



Using this, i got all the fields as a column in gridview as expected. However i only wanted selected fields to be displayed in grid and not all fields.. How can I do it.???
in client side, I had added bound fields but that resulted to repetition of columns in grid<columns> . help me solve the issue..

解决方案

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //here apply your condition
        if(Request.QueryString["name"] == "all")
        e.Row.Cells[<index_of_cell>].Visible = true;
        else
        e.Row.Cells[<index_of_cell>].Visible = false;
    }
}


i added autogeneratedcolumn and set it to true and added column field and properties manually and it worked,.,


这篇关于如何仅在gridview中显示选定的列,其中gridview列元素在运行时创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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