Charly66 Charly66 - 1 year ago 91
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download