A problem with binding method with event - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

A problem with binding method with event

viettrungviettrung Posts: 1Member

I have a problem with C# Web form programing.

I have tried to create a two-level menu using DataList controls. To do this, I have two DataList controls. The first one (first level) named lstProviders, contains a list of provider names, the second one (second level) named lstCategories, contains a list of product categories which is associated with the selected provider.

The second datalist has been embeded into the of the first one (in .ASPX file). To display a category list corresponding to a selected provider, in .CS file, I did:

- Declare a protected variable in DataList type:
protected System.Web.UI.WebControls.DataList lstCategories;

- Write some code in the SelectedIndexChanged method of the lstProviders as following:

private void lstProviders_SelectedIndexChanged(object sender, System.EventArgs e)
//Determine the lstCategories embeded into the selected item of lstProviders
this.lstCategories = (DataList)this.lstProviders.SelectedItem.FindControl("lstCategories");
if (lstKind != null)

//Create a new event corresponding to the SelectedIndexChanged of the lstCategories
this.lstCategories.SelectedIndexChanged += new

lstCategories.SelectedIndex = 0;

// A procedure to bind data to lstCategories lstCategories_Refresh(lstProviders.DataKeys[lstProviders.SelectedIndex].ToString());

private void lstCategories_SelectedIndexChanged(object sender, System.EventArgs e)

//Some simple code. Label is a Label control declared above.
Label.Text = lstCategories.DataKeys[lstCategories.SelectedIndex].ToString();


The method SelectedIndexChanged of lstProviders goes well (that means, can display the category list corresponding to some selected provider), but the one of lstCategories has no reaction.

Can you help me ?

Thanks in advance.


Sign In or Register to comment.