我有一个下拉列表框,如下所示。在某些情况下,在数据绑定事件中,我想删除其bitActive设置为0(不活动)的项目。我没有在selectCommand中放置WHERE bitAcive!= 0,因为我只想在某些条件下将其删除。有什么办法可以迭代项目并检查bitActive的值吗?如何根据ASP.net中的列名获取ListItem?
<tr>
<td width="30%" align="right">Location<span class="littlefont">*</span></td>
<td width="70%" align="left">
<asp:DropDownList ID="ddlLocation" runat="server"
DataSourceID="SqlDSLocation" DataTextField="txtRefLocation_Name"
DataValueField="intRefLocation_ID" ondatabound="ddlLocation_DataBound">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDSLocation" runat="server"
ConnectionString="<%$ ConnectionStrings:SPRConnectionString %>"
SelectCommand="SELECT DISTINCT [intRefLocation_ID], [txtRefLocation_Name], [location], [bitActive] FROM [tblRefLocation] ORDER BY [intRefLocation_ID]">
</asp:SqlDataSource>
</td>
</tr>
不要骂海报的答案之前过滤数据源,但这既不是解决问题的有效或优雅的方式... – 2012-04-02 18:31:09
@JamesJohnson不,这听起来不像批评* = * +1)你的答案,它*非常优雅! – jadarnel27 2012-04-02 18:40:06
我真的没有批评你,因为你坚持OP已经使用的实现。我只是指出有更有效的方法。我希望你不要把它当作你的轻微,因为我看到你发布了一些可靠的代码。 – 2012-04-02 18:50:13