Is it possible to return a string using event : dropdownlist_Onselectedindexchange(object sender,eventargs e)?
Is it possible to return a string using开发者_C百科 event : dropdownlist_Onselectedindexchange(object sender,eventargs e)?
As others have already stated, "You cannot return anything from an event."
But, to perform whatever you want to perform, you can store the value in a variable that is accessible both inside the event and outside it.
For Example-
You wanted to achieve something like this:
string str = dropdownlist_Onselectedindexchange(object sender,eventargs e);
Now, you cannot actually do that, so here;s what you can do:
string str;
protected void dropdownlist_Onselectedindexchange(object sender,eventargs e)
{
DropDownList ddl_temp = (DropDownList)sender;
str = ddl_temp.SelectedValue; //The SelectedValue property is used to get the
//SelectedValue of the DropDownList as a string.
}
Hope This helps.
No, you cannot return anything from this event since the method signature returns void.
It might help if you explain what you are trying to achieve by editing your question, then people are more likely to be able to come-up with a solution.
dropdownlist_Onselectedindexchanged event will be void by default and it cannot return any value. Events are not meant to work that way. If you need to get any value from inside the event, you can assign the same into any other variable that is accessible outside the event code. or you can assign the same to a text box if needed.
*Hope this helps,
精彩评论