文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Select a matching row of WebCombo control based on DataValue

Select a matching row of WebCombo control based on DataValue

时间:2010-08-27  来源:yuzhangqi

Considering the following scenario:The user selected an item in a WebCombo control then do a "save" action, when he re-enter this page, we want the Webcombo control select the value matching the data from the database.

Let's look at an example as below.

Supposed that the "Service" WebCombo has a DataTextField named "Code" and a DataValueField named "ID". Now we want to select a row by matching the DataValue of the control. Normally the code looks like below.

Dim serviceValue as String = LoadServiceValueFromDatabse()

ServiceWebCombo.DataValue = serviceValue

However, this did not work for WebCombo control.

Let's try another way as below to see if it will work.

Dim cell As New UltraGridCell
cell = ServiceWebCombo.FindByValue(strTempSetting)
If Not cell Is Nothing Then
ServiceWebCombo.SelectedIndex = cell.Row.Index
End If

However cell object returns Nothing,that's to say we can not find the matching DataValue. This way is not feasible.

Now Let's try this way: iterate items of WebCombo control to find the matching item, if found then select it, else none is selected. The code looks like below.

Private Sub SelectWebComboItem(ByRef control As WebCombo, ByVal dataValue As String)
For Each row As UltraGridRow In control.Rows
If row.Cells(1).Value.ToString().Equals(dataValue) Then
control.SelectedIndex = row.Index
Exit For
End If
Next
End Sub

If you don't like this approach, there is an alternative you can choise - using client side javascript api to select matching data value.

Supposed we have got the DataValue to match from server side in client side. First we got the client WebCombo Object using the utility function igcmbo_getComboById().

var serviceValue;

var oCombo = igcmbo_getComboById('ServiceWebCombo');

then using setDataValue() to select the matching row in the drop-down.

oCombo.setDataValue(serviceValue) ;

If you can get the row index of the matching row, you can code as such.

oCombo.setSelectedIndex(index);

If you want to select a row by matching the DisplayValue property of WebCombo control, it is very easy.

Server side code:

ServiceWebCombo.DisplayValue = <targetValue>

Client side code:

oCombo.setDisplayValue(<targetValue>);

References:

http://help.infragistics.com/Help/NetAdvantage/ASPNET/2009.1/CLR3.5/html/WebCombo_Object_CSOM.html

http://help.infragistics.com/Help/NetAdvantage/ASPNET/2010.2/CLR4.0/html/Infragistics4.WebUI.WebCombo.v10.2~Infragistics.WebUI.WebCombo.WebCombo_members.html


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载