[英]How to add if-else statement to change BoundFields of GridView
I am trying to do something like the code below: 我正在尝试做类似下面的代码:
<%= if(ddlChoice.SelectedItem.Value ==1) { %>
<asp:BoundField DataField="FirstName" HeaderText="First Name">
<HeaderStyle HorizontalAlign="Left" /></asp:BoundField>
<asp:BoundField DataField="LastName" HeaderText="Last Name">
<HeaderStyle HorizontalAlign="Left" /></asp:BoundField>
<%= } else { %>>
<asp:BoundField DataField="Name" HeaderText="Name">
<HeaderStyle HorizontalAlign="Left" /></asp:BoundField>
<%= } %>
I have a GridView
, now I want to add if-else condition to change available BoundField
s according to selected item in DropDownList
... Please Guide me !!! 我有一个
GridView
,现在我想添加if-else条件,以根据DropDownList
选定项更改可用的BoundField
……请指导我!
In short: You cannot place your if
statement between BoundField
s as you are trying to do. 简而言之:您不能像尝试那样在
BoundField
之间放置if
语句。
As an alternative solution, you could change the Visible
property of each BoundField
either from code behind or by setting a boolean value to that attribute in your .aspx file. 作为一种替代解决方案,可以从代码后面或通过为.aspx文件中的该属性设置布尔值来更改每个
BoundField
的Visible
属性。
Another alternative solution is to have more than one GridView
and change their visibility upon user selection. 另一种替代解决方案是拥有多个
GridView
并根据用户选择更改其可见性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.