aspxcombobox显示valuefield而不是textfield

时间:2017-08-03 07:58:40

标签: javascript asp.net vb.net devexpress aspxgridview

我有一个处理批量编辑模式的aspxgridview。 该方案是当我更改产品ID 列值时, Version Id 列的组合框将重新填充与产品对应的版本。一切都很好。产品正确填充以及版本,但在其默认值上显示valuefield而不是textfield,当我尝试再次重新填充产品,以便版本将级联它似乎没关系。只是使用显示valuefield而不是textfield的默认值。任何帮助将非常感激。谢谢。请参阅下面的代码。

的JavaScript

<script type="text/javascript">
    var curentEditingIndex;
    var lastCountry = null;
    var isCustomCascadingCallback = false;
    function CountriesCombo_SelectedIndexChanged(s, e) {
        lastCountry = s.GetValue();
        isCustomCascadingCallback = true;
        RefreshData(lastCountry);
    }
    function CitiesCombo_EndCallback(s, e) {
        if (isCustomCascadingCallback) {
            if (s.GetItemCount() > 0)
                sampleGrid2.batchEditApi.SetCellValue(curentEditingIndex, "chndtl_verid", s.GetItem(0).value);
            isCustomCascadingCallback = false;
        }
    }

    function OnBatchEditStartEditing(s, e) {
        curentEditingIndex = e.visibleIndex;
        var currentCountry = sampleGrid2.batchEditApi.GetCellValue(curentEditingIndex, "chndtl_prodid");
        if (currentCountry != lastCountry && e.focusedColumn.fieldName == "chndtl_verid" && currentCountry != null) {
            lastCountry = currentCountry;
            RefreshData(currentCountry);
        }
    }

    function RefreshData(countryValue) {
        hf.Set("CurrentCountry", countryValue);
        version_editor.PerformCallback();
    }

</script>

的SqlDataSource

<asp:SqlDataSource ID="Product" runat="server" ConnectionString="<%$ ConnectionStrings:DDS %>"         
        SelectCommand="SELECT [p_pcode], [p_pname] FROM [product] WHERE ([p_stat] = @p_stat)  ORDER BY [p_pname]">
             <SelectParameters>
                 <asp:Parameter DefaultValue="A" Name="p_stat" Type="String" />
                  <asp:SessionParameter DefaultValue="" Name="p_advcde" SessionField="advcde" 
                     Type="String" />
             </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="Version" runat="server" ConnectionString="<%$ ConnectionStrings:DDS %>"         
        SelectCommand="SELECT [v_matid], [v_version] FROM [version] WHERE (v_vpcode = @v_vpcode) ORDER BY [v_version]">
             <SelectParameters>
                 <asp:Parameter DefaultValue="" Name="v_vpcode" Type="String" />
                  </SelectParameters>
        </asp:SqlDataSource>

前端

<dx:ASPxGridView ID="ASPxGridView2" ClientInstanceName="sampleGrid2" runat="server"
        AutoGenerateColumns="False" DataSourceID="fordtl" Theme="Material"  KeyFieldName = "chndtl_id"
        Font-Size="11px" CssClass="ChangeEdit" OnCellEditorInitialize="sampleGrid2_CellEditorInitialize">
    <SettingsEditing Mode="Batch"></SettingsEditing>

    <dx:GridViewDataComboBoxColumn FieldName="chndtl_prodid">
        <PropertiesComboBox EnableCallbackMode="true" CallbackPageSize="30"  DataSourceID="Product" ValueField="p_pcode" TextField="p_pname" ValueType="System.Int32">
        <ClientSideEvents SelectedIndexChanged="CountriesCombo_SelectedIndexChanged" />
        </PropertiesComboBox>
    </dx:GridViewDataComboBoxColumn>

    <dx:GridViewDataTextColumn FieldName="chndtl_prod" visible="false"
        ShowInCustomizationForm="True" VisibleIndex="4">
        <SettingsHeaderFilter>
        <DateRangePickerSettings EditFormatString="" />
        </SettingsHeaderFilter>
    </dx:GridViewDataTextColumn>

    <dx:GridViewDataTextColumn FieldName="chndtl_version" visible="true"
        ShowInCustomizationForm="True" VisibleIndex="5" >
    </dx:GridViewDataTextColumn>

    <dx:GridViewDataComboBoxColumn FieldName="chndtl_verid" ShowInCustomizationForm="True" VisibleIndex="6" >
        <PropertiesComboBox EnableCallbackMode="true" OnItemRequestedByValue="OnItemRequestedByValue" 
        OnItemsRequestedByFilterCondition="OnItemsRequestedByFilterCondition"   CallbackPageSize="30" 
        TextField = "v_version" ValueField = "v_matid" ValueType ="System.Int32">
        </PropertiesComboBox>
    </dx:GridViewDataComboBoxColumn>

    </dx:ASPxGridView>

后端

 Protected Sub sampleGrid2_CellEditorInitialize(ByVal sender As Object, ByVal e As ASPxGridViewEditorEventArgs)
        If e.Column.FieldName = "chndtl_prodid" Then
            e.Editor.ClientInstanceName = "product_editor"
            Dim cmb_prod As ASPxComboBox = CType(e.Editor, ASPxComboBox) 
            cmb_prod.DataSourceID = "Product"
        cmb_prod.ValueField = "p_pcode"
        cmb_prod.TextField = "p_pname"
        cmb_prod.ClientInstanceName = "product_editor"
        cmb_prod.ValueType = GetType(Integer)
        cmb_prod.DataBindItems()
        End If
        If e.Column.FieldName <> "chndtl_verid" Then
            Return
        End If
        Dim editor = CType(e.Editor, ASPxComboBox)
        editor.ClientInstanceName = "version_editor"
        editor.TextField = "v_version"
        editor.ValueField = "v_matid"
        editor.ValueType = GetType(String)
        editor.DataBindItems()
        editor.ClientSideEvents.EndCallback = "CitiesCombo_EndCallback"

    End Sub
    Protected Sub OnItemsRequestedByFilterCondition(ByVal source As Object, ByVal e As ListEditItemsRequestedByFilterConditionEventArgs)
        Dim comboBox As ASPxComboBox = DirectCast(source, ASPxComboBox)
        Dim country As Integer = Me.GetCurrentCountry()
        Version.SelectParameters.Clear()
        Version.SelectParameters.Add("filter", TypeCode.String, String.Format("%{0}%", e.Filter))
        Version.SelectParameters.Add("startIndex", TypeCode.Int32, (e.BeginIndex + 1).ToString())
        Version.SelectParameters.Add("endIndex", TypeCode.Int32, (e.EndIndex + 1).ToString())
        If country <> -1 Then
            Version.SelectParameters.Add("v_vpcode", TypeCode.Int32, country.ToString())
            Version.SelectCommand = "SELECT [v_matid], [v_version] FROM (select [v_matid], [v_version], row_number() over (order by t.[v_matid]) as [rn] from [version] as t where ([v_version] LIKE @filter And [v_vpcode] = @v_vpcode)) as st where st.[rn] between @startIndex and @endIndex"
        Else
            Version.SelectCommand = "SELECT [v_matid], [v_version] FROM (select [v_matid], [v_version], row_number() over (order by t.[v_matid]) as [rn] from [version] as t where ([v_version] LIKE @filter)) as st where st.[rn] between @startIndex and @endIndex"

        End If
        comboBox.DataSource = Version
        comboBox.ValueField = "v_matid"
        comboBox.TextField = "v_version"
        comboBox.ValueType = GetType(String)
        comboBox.DataBindItems()

    End Sub

    Protected Sub OnItemRequestedByValue(ByVal source As Object, ByVal e As ListEditItemRequestedByValueEventArgs)
        If e.Value Is Nothing Then
            Return
        End If
        Dim comboBox As ASPxComboBox = DirectCast(source, ASPxComboBox)
        Version.SelectParameters.Clear()
        Version.SelectCommand = "SELECT [v_matid], [v_version] FROM [version] WHERE (v_vpcode = @v_vpcode) ORDER BY [v_version]"
        Version.SelectParameters.Add("v_vpcode", TypeCode.String, e.Value.ToString())
        Version.DataBind()
        comboBox.DataSource = Version
        comboBox.ValueType = GetType(String)
        comboBox.ValueField = "v_matid"
        comboBox.TextField = "v_version"
        comboBox.DataBind()
    End Sub

    Private Function GetCurrentCountry() As Integer
        'INSTANT VB NOTE: The variable id was renamed since Visual Basic does not handle local variables named the same as class members well:
        Dim id_Renamed As Object = Nothing
        If hf.TryGet("CurrentCountry", id_Renamed) Then
            Return Convert.ToInt32(id_Renamed)
        End If

        Return -1
    End Function

0 个答案:

没有答案