forum

Home / DeveloperSection / Forums / DropDownList not getting populated from Stored Procedure

DropDownList not getting populated from Stored Procedure

Pravesh Singh 1756 28-Aug-2014

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.


Updated on 28-Aug-2014

Can you answer this question?


Answer

1 Answers

Liked By