简体   繁体   English

在单独的GridViews中显示DataTable数据C#Asp.Net

[英]Display DataTable data in Seperate GridViews C# Asp.Net

I have an aspx page with GridViews. 我有一个带有GridViews的aspx页面。 I am using the gridview to act like a questionnaire. 我正在使用gridview充当问卷。 In a GridView, there are 4 Columns(Name, Company, Question, Answer) and 5 rows with textbox. 在GridView中,有4列(名称,公司,问题,答案)和带有文本框的5行。 There is a TextBox on the header where you type your name, So there are a total of 6 TextBox. 标头上有一个文本框,您可以在其中键入名称,因此共有6个文本框。 After saving, the table looks like this: 保存后,该表如下所示:

name1 | company1 | question1 | answer1
name1 | company1 | question2 | answer2
name1 | company1 | question3 | answer3
name1 | company1 | question4 | answer4
name1 | company1 | question5 | answer5

name2 | company1 | question1 | answer1
name2 | company1 | question2 | answer2
name2 | company1 | question3 | answer3
name2 | company1 | question4 | answer4
name2 | company1 | question5 | answer5

and so on. 等等。 Now my problem is, I don't know how to display them on separate gridviews after saving in Database. 现在我的问题是,保存到数据库后,我不知道如何在单独的网格视图上显示它们。 Say I want to display all records from company1, name1 's records should be displayed in a gridview and name2 's records should be displayed in a separate gridview. 假设我要显示company1的所有记录, name1的记录应显示在gridview中, name2的记录应显示在单独的gridview中。 I need this for my Search Function. 我的搜索功能需要此功能。 How can I do this? 我怎样才能做到这一点?

Please look at this.. 请看这个。

DataView dv = datatablename.DefaultView;
//get unique companies
DataTable distinctcompanynames = dv.ToTable(true,"companycolumnname");

foreach (DataRow dr in distinctgrouptype.Rows)
    {

        dv.RowFilter = "itemgrouptype='"+dr[0].ToString()+"'";
        //get different DataViews
        DataView singltable = dv.ToTable().DefaultView;  
        //here you can bind          
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM