Charly66 Charly66 - 3 months ago 36
ASP.NET (C#) Question

Populate a dropdownlist with objectdatasource

I'm trying to populate a dropdownlist with an objectdatasource programatically. It's a user control, so in my ascx I have this:

<asp:ObjectDataSource ID="odsFicheros" runat="server"
onselecting="odsFicheros_Selecting" SelectMethod="ejecutaconsultaFicheros" TypeName="DatosGW.ControlBuscador">


<asp:DropDownList ID="cmbFicheros" runat="server" CssClass="form-control"
DataTextField="fichero" DataValueField="fichero" DataSourceID="odsFicheros"
ondatabound="cmbFicheros_DataBound" AutoPostBack="True"

On the code behind I do this:

protected void Page_Load(object sender, EventArgs e)

odsFicheros.TypeName = "DatosGW.ControlBuscador";
odsFicheros.SelectMethod = "ejecutaconsultaFicheros";
Parameter consultas = new Parameter(consulta, TypeCode.String);

cmbFicheros.DataSource = odsFicheros;


And finally on my ControlBuscador class I have the method which returns a datatable, but it doesn't work, why?. If you need more details, please let me know it.


In Visual Studio, I did this with the wizard on the Selectin property:

 e.InputParameters["consulta"] = hfConsulta.Value; 

I created a HiddenField with the parameter I want, so now it's working