2010-11-27 3 views
0

Qu'est-ce qui provoque une erreur dans mon code ci-dessous:erreur est affiché en fonction

public void SetOperationDropDown() 
{ 
    if(CmbOperations.Items.Count == 0) 
    { 
     //ByDefault the selected text in the cmbOperations will be -SELECT OPERATIONS-. 

     cmbOperations.SelectedItem = "-SELECT OPERATIONS-"; 

     //This is for adding four operations with value in operation dropdown 
     cmbOperations.Items.Insert(0, "PrimaryKeyTables"); 
     cmbOperations.Items.Insert(1, "NonPrimaryKeyTables"); 
     cmbOperations.Items.Insert(2, "ForeignKeyTables"); 
     cmbOperations.Items.Insert(3, "NonForeignKeyTables"); 
     cmbOperations.Items.Insert(4, "UPPERCASEDTables"); 
     cmbOperations.Items.Insert(5, "lowercasedtables"); 
    } 
    else 
    { 
     int? cbSelectedValue = null; 

     //OP ERROR SHOWN HERE 
      if(!string.IsNullOrEmpty(cmbOperations.SelectedValue)) 

     cbSelectedValue = convert.toInt32(cmbOperations.SelectedValue); 
    } 

    //load your combo again 

    //OP ERROR SHOWN HERE 
    if(cbSelectedValue != null) 

    cmbOperations.SelectedValue = cbSelectedValue.ToString(); 
} 

(L'erreur se produit spécifiquement dans ce bout de code: cbSelectedValue.ToString();)

+0

Quelle erreur est affichée? – siride

+0

serait bon de savoir quelle est exactement l'erreur qui est affichée? – BrokenGlass

Répondre

3

SelectedValue est un objet, pas chaîne. Vous devez donc le convertir en une chaîne:

if(cmbOperations.SelectedValue != null && !cmbOperations.SelectedValue.ToString() == string.Empty) 
+0

ok il est résolu – Srivastava

+0

@Srivastava Ensuite, acceptez la réponse – Foole