GRChandrashekar
asked on
Adding first blank row to combobox
Hi
I am populating the combobox with following code. I would like to ADD AND display a blank row as first row while loading the combobox and want to get rid of -1.
private void Fillcmbmenusubgroupid()
{
try
{
bucketmenusubgroup.Predica teExpressi on.Add(Men usubgroupF ields.Flag ==
StandardFlag.recordvalidfl ag);
adaptermenusubgroup.FetchE ntityColle ction(data sourcemenu subgroup, bucketmenusubgroup,
0,
new SortExpression(
MenusubgroupFields.Descrip tion |
SortOperator.Ascending));
cmbmenusubgroupid.DataSour ce = datasourcemenusubgroup;
cmbmenusubgroupid.ValueMem ber = "MENUSUBGROUPID";
cmbmenusubgroupid.DisplayM ember = "DECRIPTION";
cmbmenusubgroupid.Selected Index = -1;
}
catch (Exception ex)
{
GlobalErrorHandler.LogMess age(ex.Sta ckTrace);
}
finally
{
adaptermenusubgroup.CloseC onnection( );
}
}
I am populating the combobox with following code. I would like to ADD AND display a blank row as first row while loading the combobox and want to get rid of -1.
private void Fillcmbmenusubgroupid()
{
try
{
bucketmenusubgroup.Predica
StandardFlag.recordvalidfl
adaptermenusubgroup.FetchE
0,
new SortExpression(
MenusubgroupFields.Descrip
SortOperator.Ascending));
cmbmenusubgroupid.DataSour
cmbmenusubgroupid.ValueMem
cmbmenusubgroupid.DisplayM
cmbmenusubgroupid.Selected
}
catch (Exception ex)
{
GlobalErrorHandler.LogMess
}
finally
{
adaptermenusubgroup.CloseC
}
}
ASKER
Sorry This is winforms
Try Create a object of ListItem specify value and text and then set the selected property of the listitem object to true and add listItem object to dropdownlist items collection. If the default that you want to set is already in your dropdown list then you can iterate over dropdownlist Items collection and set the selected property of the desired item in the collection.
ASKER
Can I have code example to match my code ?
ASKER
Can I have code example to match my code ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Not getting first line
var emptyItem = new myitem();
"myitem" cannot resolve symbol
var emptyItem = new myitem();
"myitem" cannot resolve symbol
<asp:ListItem Text="Default text" Value="Default value" />
</asp:DropDownList>
Append data bound items = true make sure that it will not remove your default item