Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42321

Having Trouble with dropdownlist Selection Changing

$
0
0
I have two dropdownlists on my page that are related to one another, and are built dynamically. I did not write the original code, but I believe it is using AJAX so the whole page doesn't postback when the ddl selection changes. The first ddl is Status and the second is ContractType. Here is the code for the event handler:

Code:

        protected void Status_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                DropDownList status = (DropDownList)sender;
                string selectedStatusId = status.SelectedItem.Value;
                string subscriberId = status.ID.Replace(STATUS_DROPDOWN_ID_BASE, "");
                string contractTypeId = CONTRACT_TYPE_DROPDOWN_ID_BASE + subscriberId;
                //DropDownList contractTypeDropDown = (DropDownList)Page.FindControl(contractTypeId);
                DropDownList contractTypeDropDown = (DropDownList)DataTable.FindControl(contractTypeId);
                //Set up the data.
                DataView view = statusAndContractTypeData.Tables[TABLE_NAME_CONTRACT_TYPE].DefaultView;
                view.RowFilter = String.Format("StatusId = '{0}'", selectedStatusId);
                contractTypeDropDown.DataSource = view;
                //contractTypeDropDown.DataMember = TABLE_NAME_CONTRACT_TYPE;
                contractTypeDropDown.DataTextField = "Description";
                contractTypeDropDown.DataValueField = FIELD_CONTRACT_TYPE_ID;



                contractTypeDropDown.DataBind();
            }
            catch (Exception ex)
            {
                //base.PublishError(ex);

            }

        }

Here is some of my debugging info:


? view.Count
4
? view.Table.Rows.Count
20
? contractTypeDropDown.SelectedValue
"E "
? contractTypeDropDown.Items.Count
4
? contractTypeDropDown.Items[0]
{Employee Only}
Attributes: {System.Web.UI.AttributeCollection}
Enabled: true
Selected: true
Text: "Employee Only"
Value: "E "
? contractTypeDropDown.Items[1]
{Employee & Spouse}
Attributes: {System.Web.UI.AttributeCollection}
Enabled: true
Selected: false
Text: "Employee & Spouse"
Value: "ES"
? contractTypeDropDown.Items[2]
{Employee & Child(ren)}
Attributes: {System.Web.UI.AttributeCollection}
Enabled: true
Selected: false
Text: "Employee & Child(ren)"
Value: "EC"
? contractTypeDropDown.Items[3]
{Family}
Attributes: {System.Web.UI.AttributeCollection}
Enabled: true
Selected: false
Text: "Family"
Value: "F4"
? ex.Message
"'ContractType3927459' has a SelectedValue which is invalid because it does not exist in the list of items.\r\nParameter name: value"

I commented out the event handler since this snapshot, just to see what would happen, but when I was hitting it you can see what ex.Message was. I don't understand why it says the SelectedValue is invalid when I see the selected value is "E " and that is one of the four items in the ddl.

I spent an entire day yesterday on this and can't afford another whole day.

Thanks if you see anything I am missing.

Viewing all articles
Browse latest Browse all 42321

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>