找到你要的答案

Q:ASPXGridView cascading input controls on edit mode

Q:套件中的级联输入控件在编辑模式

My ASPxGridView is used for data entry of phone numbers. I have a ComboBox used to get the "type" of the number (phone, cell phone, fax, etc.).

I also have a TextBox to get the actual number. I need to set the NullText of the TextBox to either a sample phone or cell number, depending on the selected value of ComboBox.

This would be easy if I had to fill another ComboBox according to a ComboBox as explained in this demo.

But a TextBox doesn't have a CallBack where I could do stuff that I need.

My ASPX Code:

<dx:ASPxGridView ID="gridPhones" runat="server"     ClientInstanceName="gridPhones" EnableRowsCache="false" 
                            AutoGenerateColumns="false" KeyFieldName="TemporaryId" Width="100%"
                            EnableCallBacks="True"
                            OnRowDeleting="gridPhones_RowDeleting"
                            OnRowInserting="gridPhones_RowInserting" 
                            OnRowUpdating="gridPhones_RowUpdating"
                            OnCellEditorInitialize="gridPhones_CellEditorInitialize">
  <Columns>
      <dx:GridViewCommandColumn Visible="true">
          <EditButton Visible="true"></EditButton>
          <UpdateButton Visible="true"></UpdateButton>
          <CancelButton Visible="true"></CancelButton>
      </dx:GridViewCommandColumn>
      <dx:GridViewDataCheckColumn FieldName="IsMain">
          <EditFormSettings Visible="True" VisibleIndex="1"></EditFormSettings>
      </dx:GridViewDataCheckColumn>
      <dx:GridViewDataTextColumn FieldName="TypeTitle">
          <EditFormSettings Visible="False"></EditFormSettings>
      </dx:GridViewDataTextColumn>
      <dx:GridViewDataComboBoxColumn FieldName="Type" Visible="False">
          <EditFormSettings Visible="True" VisibleIndex="2"></EditFormSettings>
          <PropertiesComboBox ClientInstanceName="cbPhoneType">
              <ValidationSettings Display="Dynamic" ErrorDisplayMode="Text">
              </ValidationSettings>                                            
          </PropertiesComboBox>
      </dx:GridViewDataComboBoxColumn>
      <dx:GridViewDataTextColumn FieldName="CountryCode">
          <EditFormSettings Visible="True" VisibleIndex="3">          </EditFormSettings>
      </dx:GridViewDataTextColumn>
      <dx:GridViewDataTextColumn FieldName="CityCode">
          <EditFormSettings Visible="True" VisibleIndex="4"></EditFormSettings>
      </dx:GridViewDataTextColumn>
      <dx:GridViewDataTextColumn FieldName="Phone">
          <EditFormSettings Visible="True" VisibleIndex="5">                                        </EditFormSettings>
      </dx:GridViewDataTextColumn>
    </Columns>
    <SettingsEditing Mode="EditForm"  EditFormColumnCount="5" />
    <SettingsBehavior AllowFocusedRow="True" />
</dx:ASPxGridView>

My C# code:

protected void gridPhones_RowDeleting(object sender, ASPxDataDeletingEventArgs e) {...}

protected void gridPhones_RowInserting(object sender, ASPxDataInsertingEventArgs e) {...}

protected void gridPhones_RowUpdating(object sender, ASPxDataUpdatingEventArgs e) {...}

protected void gridPhones_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
    var grid = sender as ASPxGridView;

    if (!grid.IsEditing)    
        return;

    if (e.Column.FieldName == "Type")
    {
        var combo = e.Editor as ASPxComboBox;
        combo.Font.Name = "Tahoma";
        if (combo.Items.Count == 0)
        {
            var types = LookupManager.Instance.GetAllByEnum<PhoneType>();
            combo.DataSource = types.OrderByDescending(p => p.Value);
            combo.TextField = "Title";
            combo.ValueField = "Value";
            combo.DataBind();
        }
    }
    else if (e.Column.FieldName == "CountryCode")
    {
        var txt = e.Editor as ASPxTextBox;
        txt.NullText = @"0098";
    }
    else if (e.Column.FieldName == "CityCode")
    {
        var txt = e.Editor as ASPxTextBox;
        txt.NullText = @"021";
    }
    else if (e.Column.FieldName == "Phone")
    {
        var txt = e.Editor as ASPxTextBox;
        txt.NullText = @"81022000";        //This is my conditional nulltext
        if (e.KeyValue == null)
            return;

        var val = grid.GetRowValuesByKeyValue(e.KeyValue, "Type").ToString();
        if (!string.IsNullOrEmpty(val) && val.ToInt32(0) == (int)(PhoneType.Mobile))
            txt.NullText = @"09126994040"; //This is my conditional nulltext
    }
}

我的套件中用于电话号码录入数据。我有一个组合框用来得到“型”的号码(电话、手机、传真等)。

我也有一个文本框来获得实际的数。我需要设置文本框的NullText到一个样本的电话或手机号码,根据组合框选择值。

这会如果我有去填补另一个ComboBox根据组合框在这个演示解释容易。

但一个TextBox没有回调,我所能做的事情,我需要。

我的aspx代码:

<dx:ASPxGridView ID="gridPhones" runat="server"     ClientInstanceName="gridPhones" EnableRowsCache="false" 
                            AutoGenerateColumns="false" KeyFieldName="TemporaryId" Width="100%"
                            EnableCallBacks="True"
                            OnRowDeleting="gridPhones_RowDeleting"
                            OnRowInserting="gridPhones_RowInserting" 
                            OnRowUpdating="gridPhones_RowUpdating"
                            OnCellEditorInitialize="gridPhones_CellEditorInitialize">
  <Columns>
      <dx:GridViewCommandColumn Visible="true">
          <EditButton Visible="true"></EditButton>
          <UpdateButton Visible="true"></UpdateButton>
          <CancelButton Visible="true"></CancelButton>
      </dx:GridViewCommandColumn>
      <dx:GridViewDataCheckColumn FieldName="IsMain">
          <EditFormSettings Visible="True" VisibleIndex="1"></EditFormSettings>
      </dx:GridViewDataCheckColumn>
      <dx:GridViewDataTextColumn FieldName="TypeTitle">
          <EditFormSettings Visible="False"></EditFormSettings>
      </dx:GridViewDataTextColumn>
      <dx:GridViewDataComboBoxColumn FieldName="Type" Visible="False">
          <EditFormSettings Visible="True" VisibleIndex="2"></EditFormSettings>
          <PropertiesComboBox ClientInstanceName="cbPhoneType">
              <ValidationSettings Display="Dynamic" ErrorDisplayMode="Text">
              </ValidationSettings>                                            
          </PropertiesComboBox>
      </dx:GridViewDataComboBoxColumn>
      <dx:GridViewDataTextColumn FieldName="CountryCode">
          <EditFormSettings Visible="True" VisibleIndex="3">          </EditFormSettings>
      </dx:GridViewDataTextColumn>
      <dx:GridViewDataTextColumn FieldName="CityCode">
          <EditFormSettings Visible="True" VisibleIndex="4"></EditFormSettings>
      </dx:GridViewDataTextColumn>
      <dx:GridViewDataTextColumn FieldName="Phone">
          <EditFormSettings Visible="True" VisibleIndex="5">                                        </EditFormSettings>
      </dx:GridViewDataTextColumn>
    </Columns>
    <SettingsEditing Mode="EditForm"  EditFormColumnCount="5" />
    <SettingsBehavior AllowFocusedRow="True" />
</dx:ASPxGridView>

我#代码C:

protected void gridPhones_RowDeleting(object sender, ASPxDataDeletingEventArgs e) {...}

protected void gridPhones_RowInserting(object sender, ASPxDataInsertingEventArgs e) {...}

protected void gridPhones_RowUpdating(object sender, ASPxDataUpdatingEventArgs e) {...}

protected void gridPhones_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
    var grid = sender as ASPxGridView;

    if (!grid.IsEditing)    
        return;

    if (e.Column.FieldName == "Type")
    {
        var combo = e.Editor as ASPxComboBox;
        combo.Font.Name = "Tahoma";
        if (combo.Items.Count == 0)
        {
            var types = LookupManager.Instance.GetAllByEnum<PhoneType>();
            combo.DataSource = types.OrderByDescending(p => p.Value);
            combo.TextField = "Title";
            combo.ValueField = "Value";
            combo.DataBind();
        }
    }
    else if (e.Column.FieldName == "CountryCode")
    {
        var txt = e.Editor as ASPxTextBox;
        txt.NullText = @"0098";
    }
    else if (e.Column.FieldName == "CityCode")
    {
        var txt = e.Editor as ASPxTextBox;
        txt.NullText = @"021";
    }
    else if (e.Column.FieldName == "Phone")
    {
        var txt = e.Editor as ASPxTextBox;
        txt.NullText = @"81022000";        //This is my conditional nulltext
        if (e.KeyValue == null)
            return;

        var val = grid.GetRowValuesByKeyValue(e.KeyValue, "Type").ToString();
        if (!string.IsNullOrEmpty(val) && val.ToInt32(0) == (int)(PhoneType.Mobile))
            txt.NullText = @"09126994040"; //This is my conditional nulltext
    }
}
answer1: 回答1:

Using the suggestion here I was able to set the NullText in client side as below:

Adding a client side event in PropertiesTextEdit of my PhoneType ComboBox:

<ClientSideEvents SelectedIndexChanged="function(s, e) { OnPhoneTypeChanged(s); }" />

And adding the Javascript below:

function OnPhoneTypeChanged(cbPhoneType) {
    if (cbPhoneType.GetValue().toString() == '2') {
        txtPhone.nullText = "09121111111";
        if (txtPhone.GetValue() == null)
            txtPhone.SetValue(null);
    } 
    else {
        txtPhone.nullText = "81022000";
        if(txtPhone.GetValue() == null)
            txtPhone.SetValue(null);
    }
}

使用建议在这里我能够在客户端设置nulltext如下:

加入我的表现型组合框propertiestextedit客户端事件:

<ClientSideEvents SelectedIndexChanged="function(s, e) { OnPhoneTypeChanged(s); }" />

添加下面的javascript:

function OnPhoneTypeChanged(cbPhoneType) {
    if (cbPhoneType.GetValue().toString() == '2') {
        txtPhone.nullText = "09121111111";
        if (txtPhone.GetValue() == null)
            txtPhone.SetValue(null);
    } 
    else {
        txtPhone.nullText = "81022000";
        if(txtPhone.GetValue() == null)
            txtPhone.SetValue(null);
    }
}
c#  asp.net  callback  devexpress  aspxgridview