Last post Sep 26, 2018 04:51 PM by mgebhard
Sep 26, 2018 01:46 PM|splitfire|LINK
I'm using web forms. I have dropdownlist for a crud system. When I go to the edit (update), I want to use database values for the the selected index . I've look through the forums and on google, but I'm trying to find the easiest way to achieve this.
<asp:dropdownlist id="Active" runat="server">
protected void Active_SelectedIndexChanged(object sender, System.EventArgs e)
ddlActive.SelectedIndex = ce.Active;
Sep 26, 2018 02:29 PM|mgebhard|LINK
The first step is to learn how to use/read the API documentation.
The DropDownList is a type of
ListControl. The ListControl has a SelectedValue and a SelectedItem property that sets the selections simply set the SelectedValue to the value in your database as shown in the API docs.
Keep in mind, it is not possible to provide further assistance as we can not see your database schema and have no idea how your data is stored or fetched.
Sep 26, 2018 03:30 PM|splitfire|LINK
I've read through some of those articles too. It would be nice if the API documentation had working examples too.
Sep 26, 2018 04:09 PM|mgebhard|LINK
It would be nice if the API documentation had working examples too.
As far as I know the API source code functions as expected.
Complete the Feedback section at the end of the documentation if you found a bug in the code.
Sep 26, 2018 04:12 PM|splitfire|LINK
If you could pass it along that including a working example would be beneficial, I would appreciate it.
Sep 26, 2018 04:51 PM|mgebhard|LINK
I'm not sure what you're asking as the linked document clearly shows how to assign the select value. If you are looking for an example that matches your exact business requirement then you'll need to post the relevant bits of code and SQL. It should be
as simple as executing a query and assigning the value.
void Button_Click(Object sender, EventArgs e)
// Perform this operation in a try-catch block in case the item is not found.
List.SelectedValue = ItemTextBox.Text;
MessageLabel.Text = "You selected " + List.SelectedValue + ".";
catch (Exception ex)
List.SelectedValue = null;
MessageLabel.Text = "Item not found in ListBox control.";
In the sample above the select value comes from a textbox. Replace that highlighted with code that gets the selected value from your DB table.