how to coinfigure linqdatasource in codebehind rather then in aspxpage self

  • Thread starter Thread starter mesut
  • Start date Start date
M

mesut

Hi colleagues,

how can I configure a linqdatasource in code behind. I mean I would
like to create the linqdatasource programmatically 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:LinqDataSource ID="linqDSCostCenter" runat="server"
ContextTypeName="Linq.ArtDBDataContext"
Select="new ( BusinessUnit, Type, Division,
Status, Description1, AddressID )"
TableName="FCostCenters">
</asp:LinqDataSource>
<asp:ListView ID="lvCostCenters" runat="server"
onitemdatabound="lvCostCenters_ItemDataBound"
DataSourceID="linqDSCostCenter" >
<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.ArtDBDataContext objDataContext = new
Linq.ArtDBDataContext();
objDatasource.ContextTypeName = objDataContext;
objDatasource.TableName = "CostCenters";
objDatasource.Select =
"new(BusinessUnit,Type,Division,Status,Description1,AddressID)";
lvCostCenters.DataSourceID = objDatasource;
lvCostCenters.DataBind();

thanks mesut
 
mesut said:
Hi colleagues,

how can I configure a linqdatasource in code behind. I mean I would
like to create the linqdatasource programmatically 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:LinqDataSource ID="linqDSCostCenter" runat="server"
ContextTypeName="Linq.ArtDBDataContext"
Select="new ( BusinessUnit, Type, Division,
Status, Description1, AddressID )"
TableName="FCostCenters">
</asp:LinqDataSource>
<asp:ListView ID="lvCostCenters" runat="server"
onitemdatabound="lvCostCenters_ItemDataBound"
DataSourceID="linqDSCostCenter" >
<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.ArtDBDataContext objDataContext = new
Linq.ArtDBDataContext();
objDatasource.ContextTypeName = objDataContext;
objDatasource.TableName = "CostCenters";
objDatasource.Select =
"new(BusinessUnit,Type,Division,Status,Description1,AddressID)";
lvCostCenters.DataSourceID = objDatasource;
lvCostCenters.DataBind();

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
 
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.DataSource = objCostCenter.GetCostCenter();
lvCostCenters.DataBind();

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
 
Back
Top