我有2个ddl,一个应根据选择内容在另一个中过滤数据。 两个ddl均已从.csv文件填充。有人可以帮帮我吗? DropDownList1应该过滤DropDownList2内部的内容。
protected void Page_Load(object sender, EventArgs e)
{
List<string> Namirnica = new List<String>();
List<string> EnergijakJ = new List<String>();
List<string> Energijakcal = new List<String>();
List<string> TipNamirnice = new List<String>();
ReadCSV(Namirnica, EnergijakJ, Energijakcal, TipNamirnice);
string[] envlist = Namirnica.ToArray();
string[] applist = EnergijakJ.ToArray();
string[] srvrolelist = Energijakcal.ToArray();
string[] serverlist = TipNamirnice.ToArray();
DropDownList1.DataSource = serverlist.Skip(1).Distinct();
DropDownList1.DataBind();
DropDownList2.DataSource = envlist.Skip(1).Distinct();
DropDownList2.DataBind();
}
public static void ReadCSV(List<string> Namirnica, List<string> EnergijakJ, List<string> Energijakcal, List<string> TipNamirnice)
{
StreamReader reader = new StreamReader(File.OpenRead(@"C:\Users\user\Desktop\a\PopisNamirnica.csv"));
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (!String.IsNullOrWhiteSpace(line))
{
string[] values = line.Split(';');
if (values.Length >= 4)
{
Namirnica.Add(values[0]);
EnergijakJ.Add(values[1]);
Energijakcal.Add(values[2]);
TipNamirnice.Add(values[3]);
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}