473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 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,Description 1,AddressID)";
lvCostCenters.DataSourceID = objDatasource;
lvCostCenters.DataBind();

thanks mesut
Aug 5 '08 #1
2 7018
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,Description 1,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
Aug 5 '08 #2
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
Aug 6 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: nevets2001uk | last post by:
Hi. I've just started my second ASP.NET (VB) app and I'm using codebehind this time. I'm not using visual studio but am instead coding it all in notepad (HTML, ASP.NET and CSS) I'm trying to...
12
by: Karl Hungus | last post by:
If I use a code behind class for an aspx page, what is the best way to get data from the codebehind class into my aspx page? I know about databinding, but is there a more basic way of just...
1
by: shapper | last post by:
Hello, How can I get the ID (primary key) of a record just inserted in a database table by a LinqDataSource? Thanks, Miguel
1
by: shapper | last post by:
Hello, I have a ListView connected to a LinqDataSource. It uses a table, named Tags, with 2 fields: TagId and Text. I need to add a column named active. For this I created a LinqDataSource...
0
by: Marius Manolea | last post by:
Hi, I have a strange problem, I don't receive any modifications from listview in edit mode (OldValues & NewValues are empty) <asp:ListView ID="lvEditPersonRoles" runat="server"...
2
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I am attempting to insert a simple record with LinqDataSource from a ListView, however I always get a message saying "....LinqDataSource 'dataSource' has no values to insert. Check that the...
3
by: david | last post by:
I've bound my GridView to a LinqDataSource control, but now I want to do some work in the RowDataBound event. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { var...
5
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I am using the LINQDataSource. I want to use a Parameter to for Select which is essentially a value within a code variable. I have tried using inline code for the asp:Parameter DefaultValue,...
0
by: Andy B | last post by:
I have a GridView with a LINQDataSource attached to it. My code in the aspx markup is below. I need to know why only the checkbox field for the activated column is getting updated (the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.