2017-12-18 195 views
0

我的GridView在我的web應用程序在GridView控件添加數據(Web應用程序)C#

這個網格視圖是爲了顯示3列(表,列,new_columns)

enter image description here

我想在點擊事件中顯示網格視圖,其中我想綁定第一個Field(表格)中的所有表格,並綁定GridView中下拉列表中每個表格的所有相應列,並綁定第二個下拉列表中的所有新列。

這裏是th E碼

 DataTable test = new DataTable(); 
     DataTable _dbtest = new DataTable(); 
     list_of_table_of_old_database = db.Select("", "", "", "", "", "", "", "", "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '" + old_database.Text.Trim() + "' ", ""); 
     list_of_table_of_current_database = db.Select("", "", "", "", "", "", "", "", "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '" + new_database.Text.Trim() + "' ", ""); 

     DataView view = new DataView(list_of_table_of_old_database); 


     DataTable dtTable = new DataTable(); 


     test = db.Select("", "", "", "", "", "", "", "", "select distinct k.table1 from (SELECT TABLE_NAME as table1 FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '" + old_database.Text.Trim() + "') as k INNER JOIN (SELECT TABLE_NAME as table2 FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '" + new_database.Text.Trim() + "')as a;", ""); 




     DropDownList3.Items.Clear(); 
     DropDownList3.Items.Insert(0, "--select--"); 

     DataTable dt = new DataTable(); 
     for (int i = 0; i < test.Rows.Count; i++) 
      { 

       _dbtest = db.Select("", "", "", "", "", "", "", "", "select a.fieldname from (SELECT COLUMN_NAME as fieldname FROM INFORMATION_SCHEMA.columns WHERE TABLE_SCHEMA = '" + old_database.Text.Trim() + "' and TABLE_NAME = '" + test.Rows[i][0].ToString() + "') as A LEFT JOIN (SELECT COLUMN_NAME as fieldname FROM INFORMATION_SCHEMA.columns WHERE TABLE_SCHEMA = '" + new_database.Text.Trim() + "' and TABLE_NAME = '" + test.Rows[i][0].ToString() + "') B on (A.fieldname = B.fieldname) where B.fieldname is null ", ""); 

       if (_dbtest.Rows.Count > 0) 
       { 

        //here i want to display all tables in the gridview row by row (test.Rows[i][0].ToString()) 


       } 

        // and i want to bind all columns (_dbtest) of each tables inside the loop in first dropdownlist in gridview 

       // and same columns (_dbtest) of each tables inside the loop in second dropdownlist in gridview 
      } 

我想找到綁定在GridView的,而我運行的循環數據從某種角度來說,這樣我就可以給每個字段正確的數據

,這是HTML代碼

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     Height="237px" Width="632px" onrowdatabound="GridView1_RowDataBound"> 
     <Columns> 
      <asp:TemplateField FooterText="tables" HeaderText="tables"> 
       <EditItemTemplate> 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
       </EditItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField FooterText="columns" HeaderText="columns"> 
       <ItemTemplate> 
        <asp:DropDownList ID="ddlcolumns" runat="server" 
         Height="16px" Width="181px"> 
        </asp:DropDownList> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField FooterText="vms-columns" HeaderText="vms-columns"> 
       <ItemTemplate> 
        <asp:DropDownList ID="ddl_vms_columns" runat="server" 
         Height="20px" Width="153px"> 
        </asp:DropDownList> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 

所以在最後,這種網格視圖將顯示在網格視圖該表

回答

相關問題