How to increase control over SelectedIndexChanged lists in code?

How to raise an asp.net list control's SelectedIndexChanged event in code using C #?

+3
source share
3 answers

If you ask how to manually trigger an event so that it can fire any logic: not .

Event handlers must be subtle. If you need to perform one operation from several places, extract this functionality into your own method and call the event handler. For instance:

private void CountryListBox_SelectedIndexChanged(object sender, EventArgs e)
{
    UpdateStates(ListBox1.SelectedItem.Text);
}

private void UpdateStates(string country)
{
    StateListBox.DataSource = GetStates(country);
    StateListBox.DataBind();
}

Now, instead of triggering an event SelectedIndexChanged, you simply call the method this event handler belongs to, i.e.

private void Page_Load(object sender, EventArgs e)
{
    UpdateStates("USA");
}

. , .

+15

.

  • "", lightening bolt

alt text http://img704.imageshack.us/img704/6100/listbox.jpg

  • . , .

protected void ListBox1_SelectedIndexChanged ( , EventArgs e)      {
     }

,

ListBox1_SelectedIndexChanged (, );

+4

, , ( ), , . , prerender render HTML, javascript . , . ajax - , .

0

Source: https://habr.com/ru/post/1733469/


All Articles