本文介绍了ASP:在多选列表的DropDownList selectedvalues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的asp:DropDownList中至极从SqlDataSource的填充,我需要设置选择列表上选择项目(ASP:DropDownList的或ASP:DropDownList的)。

I have asp:DropDownList wich is populated from SQLdatasource and I need to set selected items on select list (asp:DropDownList or asp:DropDownList).

下面是我的code:

      <asp:SqlDataSource runat="server" ID="sqlAihealueet"
 ConnectionString="Server=SQL2008;Database=Data;UID=123;PWD=123"
  SelectCommand="SELECT        TOP (100) PERCENT valikkoaktiivinen, alue, id, otsikko, osa1b, osa2b, osa3b, osa4b FROM            dbo.FiValikko"></asp:SqlDataSource>

  <asp:DropDownList  name="aihevalinta" id="aihevalinta"  multiple="true" DataSourceid="sqlAihealueet" DataValueField="id" DataTextField="otsikko"  class="populate placeholder"  style="width:450px; font-size:11px" runat="server">
            </asp:DropDownList>

在此页面我都等领域成立了codebehind是这样的:

On this page I have all other fields set up on codebehind like this:

vapaaselite.text = drRow.Item("vapaaselitetxt").ToString

我应该怎样做多个选择的就这一选择列表?

How should I make that multiple selected ones to that select list on?

我已经tryed这个(aihealueet数据=9682,9683):

I have tryed this (aihealueet data = "9682,9683"):

aihevalinta.SelectedValues = drRow.Item("aihealueet")

不工作,给了我错误:SelectedValues​​'不是成员'System.Web.UI.WebControls.DropDownList

not working, gives me error: SelectedValues' is not a member of 'System.Web.UI.WebControls.DropDownList

有没有办法,我可以使直接从SQL数据源selecteced项目,从sqlquery的?我可以在轻松的SQLQuery它们标记。

Is there way I could make selecteced items straight from sql datasource, from SQLquery? I could mark them easily on SQLquery.

...或者我如何做到这一点与ASP:列表框?我trye​​d同一种形式给出的。我作为选择只能得到一个项目。如果我尝试做另一种选择过的第一个选择的选择状态消失。

...or how Do I do this with asp:Listbox? I tryed same kind of aproach. I only can get one item as selected. If I try to make other one selected too the first selected ones select state disappears.

aihevalinta.SelectedValue = "9565"
aihevalinta.SelectedValue = "9566"

(其中列表形式来一样)对我来说最好的解决办法是万象的SqlDataSource选择了一个straigt。数据会是这样:

The best solution for me would be to mark selected one straigt from SQldatasource (same where the list comes form). data would be like this:

推荐答案

我不得不使周围的工作我的问题。我'肯定有有一些更好的方式来做到这一点。

I had to make work around to my problem. I'am sure there have to some better way to do this.

我的工作大约用一些jQuery脚本和非可见asp.net文本字段(valinnatlista)完成​​的。

My work around were done using some jquery script and non visible asp.net textbox field (valinnatlista).

<script>

var data= $("#valinnatlista").val() ;
var dataarray=data.split(",");

$("#aihevalinta").val(dataarray);
$("#aihevalinta").multiselect("refresh");

</script>

这篇关于ASP:在多选列表的DropDownList selectedvalues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 14:52