PC Review


Reply
Thread Tools Rate Thread

how to coinfigure linqdatasource in codebehind rather then in aspxpage self

 
 
mesut
Guest
Posts: n/a
 
      5th Aug 2008
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
 
Reply With Quote
 
 
 
 
Lloyd Sheen
Guest
Posts: n/a
 
      5th Aug 2008
mesut wrote:
> 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
 
Reply With Quote
 
mesut
Guest
Posts: n/a
 
      6th Aug 2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a public property in a master page is not visible in .aspxpage DotNetNewbie Microsoft C# .NET 4 30th Jan 2008 05:30 PM
IFrames\ASPXPage\IE7\SecondPost gh Microsoft ASP .NET 0 24th Jan 2008 04:58 PM
LinqDataSource. Get ID shapper Microsoft ASP .NET 1 23rd Dec 2007 03:35 AM
LinqDataSource shapper Microsoft ASP .NET 0 9th Nov 2007 08:45 PM
aspxpage\netscape rj Microsoft ASP .NET 1 22nd Nov 2004 09:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 AM.