Gridview 与标题中的组合框绑定
谁能告诉我如何在 ASP.Net 4 中绑定到 gridview,其中 gridview 的第一行应该是标题,第二行应该是每列的组合框,第三行是开头我的实际数据源。
如果您可以想象我想要实现的目标是能够在数据网格中的每一列与另一个数据源之间创建绑定。该绑定是通过用户在组合框中选择一个值来创建的。然而,无论我如何尝试,我似乎都无法实现这一目标。
HeaderText1 | HeaderText2 | HeaderText3
ComboBox1 | ComboBox2 | ComboBox3
DataRow1 | DataRow1 | DataRow1
DataRow2 | DataRow2 | DataRow2
DataRow3 | DataRow3 | DataRow3
Could anyone please enlighten me about how one might go about binding to a gridview in ASP.Net 4 in a scenario where the first row of my gridview should be the headers, the second should be a combobox for each column and the third is the beginning of my actual datasource.
If you can imagine what I am trying to achieve is an ability to create a binding between each column in the datagrid and another datasource. This binding is created by the user selecting a value in the comboboxes. However no matter what I try I cant seem to achieve this.
HeaderText1 | HeaderText2 | HeaderText3
ComboBox1 | ComboBox2 | ComboBox3
DataRow1 | DataRow1 | DataRow1
DataRow2 | DataRow2 | DataRow2
DataRow3 | DataRow3 | DataRow3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 TemplateColumn 轻松地将 DropDownList 放入 Gridview 列中:
并且可以轻松地将 DropDownList 绑定到另一个数据源,特别是您使用 DataSource 控件时。我不清楚你在标题中使用 DropDownLists 做什么 - 是为了过滤 GridView 中出现的行吗?
You can put a DropDownList into a Gridview column quite easily by using a TemplateColumn:
and you can bind the DropDownList to another data source quite easily, especially you're using the DataSource controls. I'm not clear on what you're doing with the DropDownLists in the header though - is it for filtering the rows that appear in the GridView?
因此,对于任何好奇的人来说,这似乎是问题的解决方案。
PS:如果有人有更好的解决方案,我很乐意听到他们:-)
以下是我在GenerateHeaderHTML()中的代码。我的代码是一个非常具体的案例(而且概率远非很好)。但请注意,您可以使用任何您想要的 html。
So for anyone curious this appears to be the solution to the problem.
PS: If anyone has any better solutions I would love to hear them :-)
The following is the code I have in the GenerateHeaderHTML(). My code is a very specific case (and prob far from great). However note that you can use any html you wish.