Home > DeveloperSection > Forums > DropDownList not getting populated from Stored Procedure
Pravesh Singh

Total Post:411

Points:2881
Posted on    August-28-2014 1:43 AM

 ASP.Net
Ratings:


 1 Reply(s)
 707  View(s)
Rate this:

I have a dropDownList that I'm trying to get populated with id's from a stored procedure. However it doesn't seem to work. this is my dropDownlist:

 <div id="newExpenseTypeDialog" style="display:none;">

        <label>Select new CaseFile:</label>

        <asp:DropDownList runat="server" ID="ddlCaseFiles" DataSourceID="dsMyCaseFiles" DataTextField="Display" DataValueField="FileID" OnPreRender="ddl_PreRender" Width="524px" />

</div>

And this is my DataSource:

<asp:SqlDataSource ID="dsMyCaseFiles" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="System.Data.SqlClient" SelectCommand="p_CaseFiles_ListActiveCaseFilesAssignedTo" SelectCommandType="StoredProcedure">

    <SelectParameters>

        <asp:SessionParameter Name="InvestigatorID" SessionField="InvestigatorID" />

        <asp:SessionParameter Name="AssignedTo" SessionField="InvestigatorID" />

    </SelectParameters>

</asp:SqlDataSource>

My Stored procedure needs two parameter. InvestigatorID and AssignedTo. It will then find return all the FileID's that match.

Now this is my .aspx.cs side code : (Page_load)

if (Request.QueryString["ExpenseID"] != null)

    {

        if (!IsPostBack)

        {

            ddlCaseFiles.DataSourceID = "dsCaseFiles";

            ddlCaseFiles.DataTextField = "Display";

            ddlCaseFiles.DataValueField = "FileID";

        }

    }

and my Pre_Render:

protected void ddl_PreRender(object sender, EventArgs e)

{

    DropDownList ddl = (DropDownList)sender;

    try

    {

        if (ddl.Items[0].Value != "-1")

            ddl.Items.Insert(0, new ListItem("--Select--", "-1"));

    }

    catch

    {

        ddl.Items.Insert(0, new ListItem("--Select--", "-1"));

    }

}

The list has the pre_render working and what not, just no data from my stored procedure.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-28-2014 2:36 AM

Hi Pravesh, 

You haven't Binded your dropdown list yet

if (Request.QueryString["ExpenseID"] != null)

{

    if (!IsPostBack)

    {

        ddlCaseFiles.DataSourceID = "dsCaseFiles";

        ddlCaseFiles.DataTextField = "Display";

        ddlCaseFiles.DataValueField = "FileID";

        ddlCaseFiles.DataBind();  //You need to Bind it here

    }

}

Hope this will help you


Don't want to miss updates? Please click the below button!

Follow MindStick