I'm kind of new to C#.NET and I've been breaking my head on this one for 2 days now.
What I am trying to do:
I have two DropDownlists: Addl and Bddl. Both DropDownlists are attached to a datasource that I specified using the "configure data source tool" of web developer 2008. Bddl is dependent on the selected item of Addl, i.e. once an item from Addl is selected with the mouse, this fires an event that tells Bddl that the data had been selected, so then Bddl adds its own items in the DropDownList (which is specified in the datasource where one of the parameters refers to the selected item of Addl, hence Bddl gets triggered by Addl and generates its own list of items).
The Problem is:
I created a function that updates DropDownlist Addl and Bddl directly from the info in my Access database. So programmatically (all in 1 function), I select an item from Addl (so far no problems since items in Addl are always generated “no dependency”). After selecting the item from Addl I expected Bddl to recognize the selected item from Addl so that it would generate its own list of items (as it usually does when I use the GUI interface with the mouse)! But Bddl at that point does not fill its list automatically with items from the query I specified in its datasource! So I am unable to select the item I want from the list!
Is this happening because no postback occurs between the time I selected an item in Addl and the time I select an item from Bddl? Is there a way I can trigger the datasource of Bddl to generate its list of items before I select my item from the list?
Should I force a postback between both dropdownlist item selections, if so how?
Should I just send a refresh event in between both selections, if so how?
I need a clean solution that does not require redefining the datasource, all the tools are there I just need to know how to trigger them at the right time, wait, and then make my selection!
Here is my code:
protected void UpdateDDlLine(ref DropDownList A,ref DropDownList B)
{
SelectDDLItem(A, itemA);
//Here I need DropDownList B to be updated before I make my
//selection???? How to trigger the query?
I've created example web form with two dropdown lists to it and name it as ddlMain and ddlSub. ddlMain is main dropdown that provides filter value to ddlSub. The code of form follows.
As you can see I defined OnSelectedIndexChanged event for ddlMain, also it has AutoPostBacks turned on. If user selects some value from ddlMain then web page will be sent to server and OnSelectedIndexChanged event will be fired.
This is my Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
return;