SirReadAlot
asked on
Cannot implicitly convert type 'object' to 'System.Web.UI.WebControls.DropDownList'
hi experts,
public void SetDropDownIndex(object sender, System.EventArgs e)
{
string strItem;
System.Web.UI.WebControls. DropDownLi st ed;
ed = sender;=================== ========== ========== ========== ========> this being highlighted
ed.SelectedIndex = ed.Items.IndexOf(ed.Items. FindByText (strItem)) ;
}
hi expert,
How do I get around this
Cannot implicitly convert type 'object' to 'System.Web.UI.WebControls .DropDownL ist'
public void SetDropDownIndex(object sender, System.EventArgs e)
{
string strItem;
System.Web.UI.WebControls.
ed = sender;===================
ed.SelectedIndex = ed.Items.IndexOf(ed.Items.
}
hi expert,
How do I get around this
Cannot implicitly convert type 'object' to 'System.Web.UI.WebControls
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The difference between mine and Bowmanje's solution is that in my case the 'ed' var will be set to 'null' if the Sender isn't a DropDownList, but it won't complain, with Bowmanje's you will get an Exception thrown if sender isn't a DropDownList.
So in my version you should do:
ed = sender as DropDownList;
if(ed == null)
{ /* ERROR */ }
and you should wrap Bowmanje's in a try/catch:
try{
ed = (DropDownList) sender;
}
catch(InvalidCastException )
{
/* ERROR */
}
Wint.
So in my version you should do:
ed = sender as DropDownList;
if(ed == null)
{ /* ERROR */ }
and you should wrap Bowmanje's in a try/catch:
try{
ed = (DropDownList) sender;
}
catch(InvalidCastException
{
/* ERROR */
}
Wint.
ASKER
thanks guys
ASKER
thanks