how to coinfigure linqdatasource in codebehind rather then in aspxpage self

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mesut

    how to coinfigure linqdatasource in codebehind rather then in aspxpage self

    Hi colleagues,

    how can I configure a linqdatasource in code behind. I mean I would
    like to create the linqdatasource programmaticall y in the code behind
    rather then dropping from the toolbox.

    below is the way working but I dropped the linqdatasource control on
    the aspx page then configured.
    <asp:LinqDataSo urce ID="linqDSCostC enter" runat="server"
    ContextTypeName ="Linq.ArtDBDat aContext"
    Select="new ( BusinessUnit, Type, Division,
    Status, Description1, AddressID )"
    TableName="FCos tCenters">
    </asp:LinqDataSou rce>
    <asp:ListView ID="lvCostCente rs" runat="server"
    onitemdatabound ="lvCostCenters _ItemDataBound"
    DataSourceID="l inqDSCostCenter " >
    <LayoutTemplate >

    I would like to do this (below) ? but get some syntax errors? so I'm
    not sure what the right syntax is?
    does anybody knows?

    LinqDataSource objDatasource = new LinqDataSource( );
    Linq.ArtDBDataC ontext objDataContext = new
    Linq.ArtDBDataC ontext();
    objDatasource.C ontextTypeName = objDataContext;
    objDatasource.T ableName = "CostCenter s";
    objDatasource.S elect =
    "new(BusinessUn it,Type,Divisio n,Status,Descri ption1,AddressI D)";
    lvCostCenters.D ataSourceID = objDatasource;
    lvCostCenters.D ataBind();

    thanks mesut
  • Lloyd Sheen

    #2
    Re: how to coinfigure linqdatasource in codebehind rather then inaspx page self

    mesut wrote:
    Hi colleagues,
    >
    how can I configure a linqdatasource in code behind. I mean I would
    like to create the linqdatasource programmaticall y in the code behind
    rather then dropping from the toolbox.
    >
    below is the way working but I dropped the linqdatasource control on
    the aspx page then configured.
    <asp:LinqDataSo urce ID="linqDSCostC enter" runat="server"
    ContextTypeName ="Linq.ArtDBDat aContext"
    Select="new ( BusinessUnit, Type, Division,
    Status, Description1, AddressID )"
    TableName="FCos tCenters">
    </asp:LinqDataSou rce>
    <asp:ListView ID="lvCostCente rs" runat="server"
    onitemdatabound ="lvCostCenters _ItemDataBound"
    DataSourceID="l inqDSCostCenter " >
    <LayoutTemplate >
    >
    I would like to do this (below) ? but get some syntax errors? so I'm
    not sure what the right syntax is?
    does anybody knows?
    >
    LinqDataSource objDatasource = new LinqDataSource( );
    Linq.ArtDBDataC ontext objDataContext = new
    Linq.ArtDBDataC ontext();
    objDatasource.C ontextTypeName = objDataContext;
    objDatasource.T ableName = "CostCenter s";
    objDatasource.S elect =
    "new(BusinessUn it,Type,Divisio n,Status,Descri ption1,AddressI D)";
    lvCostCenters.D ataSourceID = objDatasource;
    lvCostCenters.D ataBind();
    >
    thanks mesut

    You don't need a LinqDataSource. Since you know what you want to query
    simply create a linq select and bind the results to the lvCostCenters
    with a DataSource rather than a DataSourceID.

    LS

    Comment

    • mesut

      #3
      Re: how to coinfigure linqdatasource in codebehind rather then inaspx page self

      Well, I tried that but the problem is then I need to program the
      eventhandlers like Paging and Sorting in the codebehind too.

      CostCenter objCostCenter = new CostCenter();
      lvCostCenters.D ataSource = objCostCenter.G etCostCenter();
      lvCostCenters.D ataBind();

      If I use the LinqDataSource no eventhandlers needed. But for long
      reason :( I would like to define the linqdatasource in code behind and
      set the properties/methods there.

      anyhelp would be appreciated,

      thanks mesut

      Comment

      Working...