Question

My first post here and Iam an absolute beginner. Searched the web for hours. I feel that I might have approached my problem the wrong way, but here goes.

I have a Datasource that displays Loans (assets) in a Gridview.

I would like to have a ddl to filter loans. Like: `If returneddate !=null the items in grid will be free for a new loan. Selecting ex. "Available assets" in ddl runs a where query on entitydatasource and retrieves the filtered data into grid.

My code: A bit of a mess, several queries that hopefully do the same. I prefer the first one LinqtoEntities

namespace Logsys.Pages
{
    public partial class OversiktLån : Page
    {
        private LogsysEntities context = new LogsysEntities();

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected EntityDataSource LaanLedig(object sender, EventArgs e)
    {
        var ledigQuery = from laan in context.Laans
                         where laan.Returnertdato != null
                         select laan;

        foreach (var laan in ledigQuery)
        {


        }

    }



    protected void DDLlaan_SelectedIndexChanged(object sender, EventArgs e)
    {


    }

    protected void LaanEntityDataSource_QueryCreated(object sender, QueryCreatedEventArgs e)

    {

        var laanQuery1 = e.Query.OfType<Laan>();
        e.Query = from c in laanQuery1
                  where (c.Returnertdato != null)
                  select c;

How to get result of query "into" datasource and make ddl items trigger queries?

KK

Was it helpful?

Solution

protected void ddlLaan_SelectedIndexChanged(object sender, EventArgs e) { Int32 ddlvalue = Convert.ToInt32(ddlLaan.SelectedValue);

        if (ddlvalue == 1)
        {
            CLogsysEntities = new LogsysEntities();

            var ledig =
                from laan in CLogsysEntities.Laans
                where laan.Returnertdato != null
                select laan;
            LaanGridView.DataSourceID = null;
            LaanGridView.DataSource = ledig.ToList();
            LaanGridView.DataBind();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top