I have gridview in my web application
我在我的网络应用程序中有gridview
this grid view is supposed to show 3 columns (tables, columns, new_columns)
此网格视图应显示3列(表,列,new_columns)
I want to show grid view in click event in which I want to bind all tables in first Field(tables) and bind all respective columns of each table in dropdown list inside the gridview and also bind all new columns in second drop down list
我想在click事件中显示网格视图,其中我想绑定第一个Field(表)中的所有表,并在gridview内的下拉列表中绑定每个表的所有相应列,并在第二个下拉列表中绑定所有新列
here is the code
这是代码
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
}
I want to find some ways to bind data in gridview while I am running the loop, so I can give each field the right data
我想在运行循环时找到一些在gridview中绑定数据的方法,因此我可以为每个字段提供正确的数据
and this is the HTML code
这是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>
so at the end, this grid view will show all tables in grid view and each column of that table
所以最后,这个网格视图将显示网格视图中的所有表格以及该表格的每一列
1 个解决方案
#1
0
First step is load all tables and binding it to your gridView. You won`t use the event GridView1_RowDataBound to do that.
第一步是加载所有表并将其绑定到gridView。你不会使用事件GridView1_RowDataBound来做到这一点。
After you have load your tables you can use the event GridView1_RowDataBound to populate the DropDownLists. You can find a few examples explaining how to do that:
加载表后,可以使用事件GridView1_RowDataBound填充DropDownLists。您可以找到一些示例来解释如何执行此操作:
https://www.aspsnippets.com/Articles/How-to-populate-DropDownList-in-GridView-in-ASPNet.aspx
https://www.aspsnippets.com/Articles/How-to-populate-DropDownList-in-GridView-in-ASPNet.aspx
https://codepedia.info/bind-dropdownlist-inside-gridview-edit-template/
https://codepedia.info/bind-dropdownlist-inside-gridview-edit-template/
#1
0
First step is load all tables and binding it to your gridView. You won`t use the event GridView1_RowDataBound to do that.
第一步是加载所有表并将其绑定到gridView。你不会使用事件GridView1_RowDataBound来做到这一点。
After you have load your tables you can use the event GridView1_RowDataBound to populate the DropDownLists. You can find a few examples explaining how to do that:
加载表后,可以使用事件GridView1_RowDataBound填充DropDownLists。您可以找到一些示例来解释如何执行此操作:
https://www.aspsnippets.com/Articles/How-to-populate-DropDownList-in-GridView-in-ASPNet.aspx
https://www.aspsnippets.com/Articles/How-to-populate-DropDownList-in-GridView-in-ASPNet.aspx
https://codepedia.info/bind-dropdownlist-inside-gridview-edit-template/
https://codepedia.info/bind-dropdownlist-inside-gridview-edit-template/