Last post Aug 25, 2020 01:42 PM by RDesh
Aug 25, 2020 02:49 AM|RDesh|LINK
I have a dropdown that has values assigned to it. In some cases I fetch a record and display, in which case I need to show the dropdown selected value as the one I got from the Stored procedure. I tried everything, but nothing is working. I verified str
below is not NULL. It is getting the correct value.
String str = ds.Tables.Rows["ALERT_BYPASS_REASON"].ToString();
1) AlertReasonDropDown.Items.FindByText(str).Selected = true; // Nothing gets assigned. Blank (which is at index 0 is displayed)
2) AlertReasonDropDown.SelectedItem.Text = str; // This always assigns the 1st Dropdown list item as the value, not the one I am assigning (str).
3) AlertReasonDropDown.SelectedValue = str; // Again, blank assigned.
Any help will be appreciated.
Aug 25, 2020 06:23 AM|RagavanB|LINK
Hi, pls check this may help.
Aug 25, 2020 12:35 PM|RDesh|LINK
I tried this. Here is my piece of code. But it gives me NullReferenceException:.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
AlertReasonDropDown.Items.FindByValue(str).Selected = true;
Let me know if you see anything off.
Aug 25, 2020 01:42 PM|RDesh|LINK
I solved this issue. I was declaring the Dropdown instance after calling this function which was assigning value. No wonder it was throwing an exception. Thank you though!