C# 如何从ArrayList或GridView c中删除列#
有没有办法从ArrayList中删除“列” 在尝试从txt文件填充DropDownList之前,我已经建立并运行了这个站点,所以我硬输入了每个值。现在我已经从每个DropDownList中创建了一个ArrayList,这样我就可以在站点上的DataGridView中显示这些列表。唯一的问题是“Enabled”和“Selected”显示为列,我似乎无法删除ArrayList中的列,也无法指定在使用GridView.columns.remove()创建ArrayList或GridView时要引入哪些列;因为整数0、1或2似乎与任何内容都不对应,站点也没有运行,我无法指定字符串作为要删除的列标题 数据网格显示为启用的列选中的列文本值| 下面是这篇文章的代码(你可以看到我试过的东西,但没有用,我已经注释掉了): 我会继续在一个txt文件中创建一个简单的2d数组,其中包含“值”和“文本”字段,这样DropDownList就可以正确地将其拉入,但我也无法在效率非常低和令人困惑的情况下理解这一点C# 如何从ArrayList或GridView c中删除列#,c#,asp.net,arraylist,datagridview,C#,Asp.net,Arraylist,Datagridview,有没有办法从ArrayList中删除“列” 在尝试从txt文件填充DropDownList之前,我已经建立并运行了这个站点,所以我硬输入了每个值。现在我已经从每个DropDownList中创建了一个ArrayList,这样我就可以在站点上的DataGridView中显示这些列表。唯一的问题是“Enabled”和“Selected”显示为列,我似乎无法删除ArrayList中的列,也无法指定在使用GridView.columns.remove()创建ArrayList或GridView时要引入哪些
任何帮助都将不胜感激。谢谢。所以,这是我最后的解决方案。我终于想出了如何从txt文件中提取所有内容,并以我想要的方式将其放入网格中
// Populate Department GridView
// get all lines of csv file
string[] BuildingString = File.ReadAllLines(Server.MapPath("Content/BuildingsCSV.csv"));
string[] DepartmentString = File.ReadAllLines(Server.MapPath("Content/DepartmentsCSV.csv"));
// create new datatable
DataTable BuildingTable = new DataTable();
DataTable DepartmentTable = new DataTable();
// Building Table
// get the column header means first line
string[] tempbuild = BuildingString[0].Split(',');
// creates columns of gridview as per the header name
foreach (string t in tempbuild)
{
BuildingTable.Columns.Add(t, typeof(string));
}
// now retrive the record from second line and add it to datatable
for (int i = 1; i < BuildingString.Length; i++)
{
string[] t = BuildingString[i].Split(',');
BuildingTable.Rows.Add(t);
}
// Department Table
// get the column header means first line
string[] tempdept = DepartmentString[0].Split(',');
// creates columns of gridview as per the header name
foreach (string t in tempdept)
{
DepartmentTable.Columns.Add(t, typeof(string));
}
// now retrive the record from second line and add it to datatable
for (int i = 1; i < DepartmentString.Length; i++)
{
string[] t = DepartmentString[i].Split(',');
DepartmentTable.Rows.Add(t);
}
// assign gridview datasource property by datatable
BuildingGrid.DataSource = BuildingTable;
BuildingGrid.DataBind();
BuildingGrid.Rows[0].Visible = false;
DepartmentGrid.DataSource = DepartmentTable;
DepartmentGrid.DataBind();
DepartmentGrid.Rows[0].Visible = false;
foreach (DataRow drb in BuildingTable.Rows)
{
BuildingDrop.Items.Add(new ListItem(drb[0].ToString(), drb[1].ToString()));
}
foreach (DataRow drd in DepartmentTable.Rows)
{
DepartmentDrop.Items.Add(new ListItem(drd[0].ToString(), drd[1].ToString()));
}
//填充部门GridView
//获取csv文件的所有行
string[]BuildingString=File.ReadAllLines(Server.MapPath(“Content/buildingscv.csv”);
string[]DepartmentString=File.ReadAllLines(Server.MapPath(“Content/DepartmentsCSV.csv”);
//创建新数据表
DataTable BuildingTable=新DataTable();
DataTable DepartmentTable=新DataTable();
//建筑表
//获取列标题表示第一行
字符串[]tempbuild=BuildingString[0]。拆分(',');
//根据标题名称创建gridview的列
foreach(tempbuild中的字符串t)
{
Add(t,typeof(string));
}
//现在从第二行检索记录并将其添加到datatable
for(int i=1;i
DepartmentGrid.Columns[“ColumnName”]。Visible=false代码>?不幸的是,没有(我忘了把它和注释一起放进去)。获取pushback“参数1:无法从'string'转换为'int'”我建议您将数据源绑定到集合而不是ArrayList,并对要隐藏的属性使用[Browsable(false)]
属性。我相信DropDownList项是一个集合,它们只包含“enabled”和“enabled”的布尔值“被选中”,对吗?
// Populate Department GridView
// get all lines of csv file
string[] BuildingString = File.ReadAllLines(Server.MapPath("Content/BuildingsCSV.csv"));
string[] DepartmentString = File.ReadAllLines(Server.MapPath("Content/DepartmentsCSV.csv"));
// create new datatable
DataTable BuildingTable = new DataTable();
DataTable DepartmentTable = new DataTable();
// Building Table
// get the column header means first line
string[] tempbuild = BuildingString[0].Split(',');
// creates columns of gridview as per the header name
foreach (string t in tempbuild)
{
BuildingTable.Columns.Add(t, typeof(string));
}
// now retrive the record from second line and add it to datatable
for (int i = 1; i < BuildingString.Length; i++)
{
string[] t = BuildingString[i].Split(',');
BuildingTable.Rows.Add(t);
}
// Department Table
// get the column header means first line
string[] tempdept = DepartmentString[0].Split(',');
// creates columns of gridview as per the header name
foreach (string t in tempdept)
{
DepartmentTable.Columns.Add(t, typeof(string));
}
// now retrive the record from second line and add it to datatable
for (int i = 1; i < DepartmentString.Length; i++)
{
string[] t = DepartmentString[i].Split(',');
DepartmentTable.Rows.Add(t);
}
// assign gridview datasource property by datatable
BuildingGrid.DataSource = BuildingTable;
BuildingGrid.DataBind();
BuildingGrid.Rows[0].Visible = false;
DepartmentGrid.DataSource = DepartmentTable;
DepartmentGrid.DataBind();
DepartmentGrid.Rows[0].Visible = false;
foreach (DataRow drb in BuildingTable.Rows)
{
BuildingDrop.Items.Add(new ListItem(drb[0].ToString(), drb[1].ToString()));
}
foreach (DataRow drd in DepartmentTable.Rows)
{
DepartmentDrop.Items.Add(new ListItem(drd[0].ToString(), drd[1].ToString()));
}