任何方式操纵在GridView中柱的AutoGenerateColumns =真的吗? [英] Any way to manipulate the columns in GridView with AutoGenerateColumns = true?

查看:91
本文介绍了任何方式操纵在GridView中柱的AutoGenerateColumns =真的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像没有办法,如果的AutoGenerateColumns = true来操纵一个GridView的列。这里是我的情况:

It seems like there's no way to manipulate the columns of a Gridview if AutoGenerateColumns = true. Here's my scenario:

我已经得到了显示根据用户选择不同的东西不同的LINQ查询结果的通用GridView控件。我喜欢这样的事实,该工程的AutoGenerateColumns像它应该和我没有指定所有绑定列,模板列列,等...

I've got a generic GridView that displays the results of various different LINQ queries depending upon what the user selects. I like the fact that the AutoGenerateColumns works like it should and I don't have to specify all the BoundField, TemplateField columns, etc...

在最重要的是,我还编程根据需要添加其他列。被编程添加的列被渲染到自动生成的列的左侧。如果我想将其移动到正确的?

On top of that, I'm also programatically adding other columns as needed. The columns that are programatically added are rendered to the left of the autogenerated columns. What if I wanted to move them to the right?

GridView.Columns.Count只统计那些编程,自动生成没有,所以我不能重新安排我希望周围的列。如果需要的话我可以钩RowDataBound事件和隐藏的东西,但我不能重新排列。

GridView.Columns.Count only counts those that are programmed, not autogenerated, so I can't rearrange the columns I want around. I can hook the RowDataBound event and "hide" something if necessary, but I can't rearrange.

我只是不得不放弃AutoGeneratedColumns = true,并且布置它们与绑定列每个查询?有什么我可以做什么?

Do I just have to give up AutoGeneratedColumns=true, and lay them out with BoundFields for each query? Is there anything I can do?

推荐答案

您可以操纵开往这样的数据的东西:

You can manipulate things on data bound like this:

Private Sub MyGrid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Me.RowDataBound
  If Me.AutoGenerateColumns = True Then
    If e.Row.RowType = DataControlRowType.DataRow Then
          e.row.cells.add(some code here to add your special column)
    End If
    End If
End Sub

您就必须创建自己的头,但它是非常可行的。

You'd have to create your own header to but it's very doable.

这篇关于任何方式操纵在GridView中柱的AutoGenerateColumns =真的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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