shubham bhardwaj

shubham bhardwaj

  • 1.7k
  • 18
  • 5.1k

Unable to cast the object type System.-.generic.keyvaluepair

Nov 28 2014 11:54 PM
Unable to cast the object type System.-.generic.keyvaluepair into system.iconvertible
 
here is my code
 
private void LoadUniversity()
{
try
{
ObjUtility = new Utility();
 
cmbUniversity.DataSource = ObjUtility.BindUniversity(StaticInfo.Center_Code).ToList();
  //////////error is after this line (May be in BindUniversity method )/////////// 
 
cmbUniversity.DisplayMember = "Value";
cmbUniversity.ValueMember = "Key";
cmbUniversity.SelectedIndex = -1;
cmbUniversity.Text = "--Select University--";
ObjUtility = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
 
I am also giving here BindUniversity() method which is in Utility class ... here it is:------
 
public Dictionary<string, string> BindUniversity(string CenterCode)
{
ObjUniversityInfoModel = new UniversityInfoModel();
ObjUniversityInfoModel.CenterCode = CenterCode;
ObjUniversityInfoServiceClient = new UniversityInfoServiceClient();
ObjUniversityInfoModelRecordList = new List<UniversityInfoModel>();
ObjUniversityInfoModelRecordList = ObjUniversityInfoServiceClient.GetUniversityInfoRecordList(ObjUniversityInfoModel);
if (ObjUniversityInfoModelRecordList[0].Message == "Success" && ObjUniversityInfoModelRecordList[0].Status == true)
{
var Result = from s in ObjUniversityInfoModelRecordList
orderby s.UniversityID descending
select new
{
s.UniversityID,
s.UniversityName
};
ObjDictionary = new Dictionary<string, string>();
foreach (var Item in Result)
{
string U_ID = Item.UniversityID.ToString();
string U_Name = Item.UniversityName.ToString();
ObjDictionary.Add(U_ID, U_Name);
}
}
return ObjDictionary;
}
 
Help me....  
 

Answers (1)