Asp.net dropdownlist static listitems

asp.net

im working on an asp.net website with c#.
I have a dropdownlist with data from an sql database. The dropdownlist is on a gridview.

The dropdownlist is inside a templatefield, on the edititemtemplate.

The data is loaded on the dropdownlist and once a link button is pressed the dropdownlist is enabled for editing, with the corresponding value, ………….but also all the other values from the column from the database are loaded there(this last thing is something I dont want).

The dropdownlist is binded on the GridView1_RowDataBound event:

Control ctrlgridMonedaEdit = e.Row.FindControl("gridMonedaEdit");
            if (ctrlgridMonedaEdit != null)
            {
                DropDownList dd = ctrlgridMonedaEdit as DropDownList;
                //more code here
                dd.DataSource = dt;
                dd.DataValueField = "Moneda";
                dd.DataTextField = "Moneda";
                dd.DataBind();
                DataRowView rowView = (DataRowView)e.Row.DataItem;
                string tempDate = rowView["Moneda"].ToString();
                dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText(tempDate));
                sqlConn.Close();
            }

What I want is 3 values which must load when the dropdownlist is enabled for editing. And also that the corresponding value stay selected.
I have tried this:

<EditItemTemplate>
      <asp:DropDownList Width="90" runat="server" id="gridMonedaEdit" AutoPostBack="true" Enabled ="true"   >
         <asp:ListItem Value="MONEDA"> MONEDA </asp:ListItem>
                  <asp:ListItem Value="USD"> USD </asp:ListItem>
                  <asp:ListItem Value="MONEDA/USD"> MONEDA/USD </asp:ListItem>
      </asp:DropDownList>                          
</EditItemTemplate>

But these values do not show up.

How can I solve this?

Best Answer

I'd insert the static list items in the code behind after calling dataBind() on your dropdownlist.

Related Topic