在GridView控件添加数据(Web应用程序)C#
我的GridView在我的web应用程序在GridView控件添加数据(Web应用程序)C#
这个网格视图是为了显示3列(表,列,new_columns)
我想在点击事件中显示网格视图,其中我想绑定第一个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>
所以在最后,这种网格视图将显示在网格视图该表
回答:
第一步是加载的所有表并将其绑定到你的GridView的每列的所有表和。你不会使用事件GridView1_RowDataBound来做到这一点。
加载完表后,您可以使用事件GridView1_RowDataBound来填充DropDownLists。你可以找到一些例子,说明如何做到这一点:
https://www.aspsnippets.com/Articles/How-to-populate-DropDownList-in-GridView-in-ASPNet.aspx
https://codepedia.info/bind-dropdownlist-inside-gridview-edit-template/
以上是 在GridView控件添加数据(Web应用程序)C# 的全部内容, 来源链接: utcz.com/qa/261611.html