Charly66 Charly66 - 1 month ago 20
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"
OldValuesParameterFormatString="original_{0}"
onselecting="odsFicheros_Selecting" SelectMethod="ejecutaconsultaFicheros" TypeName="DatosGW.ControlBuscador">

</asp:ObjectDataSource>

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


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);
odsFicheros.SelectParameters.Add(consultas);
odsFicheros.DataBind();

cmbFicheros.DataSource = odsFicheros;

this.ejecutarConsulta();
}


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

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

Comments