how to coinfigure linqdatasource in codebehind rather then in aspxpage self

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
 
L

Lloyd Sheen

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
 
M

mesut

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top