insert item in combobox after binding it from a Dataset in c#

前端 未结 3 1454
眼角桃花
眼角桃花 2020-12-03 05:41

I have to insert \"Select\" at top after combobox is bound from dataset.i tried this but it isn\'t working.Throws error \"dataset doesn\'t have any definition for cast\".I t

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 06:06

    // cmbCategory.DataSource =(new object[] { "Select" }).Concat(this.liveReportingDalc.GetCategoriesByType(CategoryType.RegistrationType).Cast()); 
    
    
    

    You might be able to do this, but your syntax is wrong somehow.

    Maybe you can split it up until you figure it out and then compress it back into in-line functions.

    List  catData = new List  { "Select" };
    
    DataSet catByType = this.liveReportingDalc.GetCategoriesByType(CategoryType.RegistrationType);
    
    foreach(DataRow oRow in catByType.Tables[0].Rows)
    { catData.Add(oRow.ItemArray[0]); }
    
    
    

    But for this to work you need to consolidate your understanding of the data coming back from the GetCategoriesByType function. Will the objects be text like "Select"?.

    提交回复
    热议问题