Error:Control cannot fall through from one case label ('case 2:') to another
-
Thursday, April 09, 2009 11:18 AMHi,
I am peresenting the data on the page using SPGridView.My requirement is i need to add add checkboxfield as a column to the existing SPGridView.For that what i have done is i have wrritten code as below in the web part as
TemplateField checkboxCol = new TemplateField();
checkboxCol.HeaderText = "Select All";
checkboxCol.ItemTemplate = new CustomSPGridViewTemplate(ListItemType.Item, "Select All");
spgw.Columns.Add(checkboxCol);
this.Controls.Add(spgw);
in the CreateChildControls method.After that i have created another class and i have written as below
class CustomSPGridViewTemplate : ITemplate
{
ListItemType templateType;
string columnName;
public CustomSPGridViewTemplate(ListItemType type, string colname)
{
templateType = type;
columnName = colname;
}
#region ITemplate Members
public void InstantiateIn(Control container)
{
Literal lc = new Literal();
switch (templateType)
{
case ListItemType.Header:
lc.Text = "<B>" + columnName + "</B>";
container.Controls.Add(lc);
break;
case ListItemType.Item:
CheckBox checkBox = new CheckBox();
checkBox.ID = "SelectAllID";
checkBox.Visible = true;
//checkBox.DataBinding += new EventHandler(checkBox_DataBinding);
container.Controls.Add(checkBox);
}
}
But when i compile it is giving error as
'Control cannot fall through from one case label ('case 2:') to another'.Have you ever come across this scenario
Regards,
Sudheer
All Replies
-
Thursday, April 09, 2009 11:25 AM
You forgot the break statement in your second (last) case block. The complier doesn't like that. You code needs to be like :
case ListItemType.Header:
lc.Text = "<B>" + columnName + "</B>";
container.Controls.Add(lc);
break;
case ListItemType.Item:
CheckBox checkBox = new CheckBox();
checkBox.ID = "SelectAllID";
checkBox.Visible = true;
//checkBox.DataBinding += new EventHandler(checkBox_DataBinding);
container.Controls.Add(checkBox);
break;
http://jcapka.blogspot.com- Marked As Answer by Michael Washam - MSFT Friday, April 10, 2009 3:51 PM

