Select a matching row of WebCombo control based on DataValue

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.

WebCombo-Select-match-row.jpg

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 =

Client side code:

oCombo.setDisplayValue();

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

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13651903/viewspace-1037465/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13651903/viewspace-1037465/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值