我有两个下拉列表:如何使用LINQ与DropDownList的
<asp:DropDownList ID="dropdownlist1" runat="server">
<asp:ListItem>Select One</asp:ListItem>
<asp:ListItem>once</asp:ListItem>
<asp:ListItem>twice</asp:ListItem>
<asp:ListItem>thrice</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="dropdownlist2" runat="server">
<asp:ListItem>Select One</asp:ListItem>
<asp:ListItem>1/22/2014</asp:ListItem>
<asp:ListItem>1/25/2016</asp:ListItem>
</asp:DropDownList>
我如何建立LINQ做到以下几点:
- 如果任何选定的指数大于0,则使用更大条件,否则选择全部。
我做了以下内容:
GridView1.DataSource = List1
.Where(en =>
en.howManyTimes == (dropdownlist1.SelectedIndex > 0 ? dropdownlist1.SelectedItem.Value : ""))
.Select(en => new { en.TheID, en.GetFile, en.GetLink });
,我只是不知道在三元运算符的:
后。
这是我想什么:
GridView1.DataSource = List1.Where(EN => en.howManyTimes ==(如果 dropdownlist1选择指数是伟大的比0,则该值用于 howManyTimes ,否则选择任何howTimes)& & en.whatDate == (如果dropdownlist2选择的索引大于0,那么使用那个值 为whatDate,否则选择任何whatDate))。Select(en => new {en | en.GetFile,en.GetLink});
我可以请一些帮助完成它。
我希望把它们全部存放在一个LINQ查询,但我不认为这是可能的吧? – Si8