473,769 Members | 4,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Aug 5 '08 #1
2 7039
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
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.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
Aug 6 '08 #3

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

Similar topics

3
1589
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 understand how to best use codebehind to do what I want to achieve. Basically, so far I have a codebehind file for one page which works as I wanted but I want other pages to share that codebehind file. That's no problem except I want each one to...
12
1653
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 referencing the variables or calling getters? thanks in advance
1
1799
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
3913
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 custom selecting: Private Sub ldsTags_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs) Handles ldsTags.Selecting
0
2867
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" DataKeyNames="PersonId,RoleEntityGroup" DataSourceID="LDSPersonRoles"
2
3364
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 'values' dictionary contains values...." I am using a ListView with a DataSourceID of a LinqDataSource. When a new row icon is clicked....the ListView properly enters into the InsertItemTemplate....however when the ImageButton with a CommandName of...
3
6461
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 item = e.Row.DataItem; But now what do I do. When using ObjectDataSource and DataSets, I could cast that item to a DataRowView and access the properties from there.
5
2584
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, however this is not being driven. Here is my existing code... <asp:LinqDataSource ID="dataSource" runat="server" ContextTypeName="SLCMS_DB_DataContext"
0
1595
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 EditTemplate). None of the other columns get updated except for that one. Any ideas? The only column that is not able to be updated is the ID column, but that isn't even in the table. <asp:GridView ID="EternityNewsMemberList" runat="server"...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.