Using more than one table with linq datasource on custom control - asp.net

I'm probably opening myself up to a world of trouble with this one but here goes. As part of a project I have to have a method of representing a timetable for university students, showing lectures, times, rooms etc. I'm not a coding pro so I have found (and ok'd with uni) an opensource control by the name of DayPilot lite www.daypilot.org. I have that installed now and am beginning the arduous task of figuring out what to do with it. I know I need to bind it to a datasource. My problem is that to give all the information I have mentioned, I need to pull data from 3 tables. When I go to set up a LinqDataSource on the aspx page I can only pick tables from one. I have been searching for ages trying to locate some info. This is the best I have came across: http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx.
However it does not make sense to me. I can't see where he actually connects more than one table to the datasource on the aspx page, in asp code. Am I missing something glaringly obvious here. Is it perhaps a case that I connect it to one table through the linq DS and then write queries to pull the rest of the data I need. In that case how would the data be shown in the calendar if I only connect to one table. Here is the asp code for the calendar anyway.
`<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="OrionDataClassesDataContext" EntityTypeName=""
Select="new (Module, Building_code, Event_type)" TableName="Events">
</asp:LinqDataSource>
<DayPilot:DayPilotCalendar ID="DayPilotCalendar1" runat="server" />`
Obviously that is very preliminary. Plenty of work to do. If someone could give some (simple) advice it would be great. Thanks....and before anyone says it, I know I need to get rid of the default names haha.

Well, I have never used LinqDataSource, or anything on the direction of what you are doing right now. I'm still using the all sql-statement-in-code-behind method. So my idea below might not work.
If I understand correctly your question above, define a view to return result of your join tables, and add the view to your DataContext. In the LinqDataSource control, set the Tablename property to the view.

Related

Security There is a Hyperlink in my GridView

There is a page in my company that contains only a GridView with some data
Today i saw this text in one of the cells (i changed a little to show to you)
[div style="display:none"]discount online BLABLABLA[a href="http://www.[randonURL].net/page/[randompage].aspx"]click[/a] new prescription coupon[/div]
I searched this text and somehow, someone inserted this in my database
How he made that?...what i can do about it?
It sounds like a classic case of SQL injection. There are a number of things you can do to prevent it. Here are a few. I would suggest reading up on it though.
On your database methods always use parameterized SQL, stored procedures or an ORM. Never use dynamic SQL. In the rare case you have to, there are ways of protecting that too. But that is a fairly long discussion.
Always encode user input. For JavaScript use the encodeURI() method. On the server side use the HtmlDecode() method.
Never show error details in the public domain. This gives hackers clues they can use.

ASp.Net GridView Updating using a stored procedure

I've read tons of sites on this. There are many "Examples" if you call some code with no explanation of how it was generated (design view vs typed) an example or just want to use simple select and update statements.
I have a Gridview. I am populating it using code from a stored proc. Now I want to edit the data. I have nothing set in the properties of the Gridview through design view (datasource, columns, etc.) My question is, how can I set this to allow editing and use a SP to send it back to the database?
Do I have to now manually create columns with code since I chose to not set properties in the design view?
Is it better to set the properties in design view and go that route? I started that way, but had problems when it came to updating with a SP.
I guess the whole do it in the designer vs do it in code thing has me confused.
I started adding RowEdit, RowCommand, etc. to the html and c#, but still don't see the EDIT/CANCEL on the webpage when I run it.
Learn to use the ObjectDataSource. It gives you maximum freedom of what way of storing the data you use - you delegate the select, update and delete to an external class where you just write your code which uses ado, linq, hibernate, a webservice or just anything.
Coding your views directly against fixed database structure would hurt you sooner or later.

Easy way to replace Data with ComboBox? Or populate ComboBox from Data

I took over a very old project written in VB6, it's a mess and I don't really know VB so it would be great if someone could help me.
I have a Data control which gets records from an Access database which I would like to replace with some kind of drop down list - I thought about ComboBox. Unfortunately I cannot get records from the database in the same way as with Data, so I thought about populating ComboBox based on what's in the Data control. How can I achieve it? Or is there a better way to do it?
My last resort is to create all database methods manually in order to replicate Data's behaviour for ComboBox but I think it's too much effort for such a small change.
Thanks in advance!
The Data control does more than just let them browse through the records, it manages the database, current record, data binding, etc.
The easiest way to do what you want is to hide/move the data control and use its .Recordset.Find*() methods.
Note that DAO is archaic and has been supersceded at least once for VB6 (with ADO)

Ideas for Quick Hierarchical Listing - .NET

I have a table in SQL Server listing corporate departments and their sections and subsections (3 levels). I would like to create some web-based listing of this, but similar to a TreeList.
I was thinking to set up nested Ajax Accordions, but it was taking me way too long to put together. I would even settle for a GridView with non-repeating column values.
Is there a way I can implement my idea without it taking me more than an hour or so for a newbie to complete? Any controls in ASP.NET or Ajax I can bind to would be great.
Thanks to Ozzy, I was able to solve this simple issue using a TreeList. Since my issue is simlper than the one in the tutorial he supplied, all I did was create DataTable for each level, and for each row I added the TreeNode (which was simply the string value of that entry). Thanks!!

asp.net - Possible to have formview edit data across multiple tables?

I am attempting to construct a formview that will edit two related objects at once.
In basic terms, I have a Linq To SQL object of teacher which has exactly one school. The formview has no problem displaying the data, but when in edit mode will only save the changes done to the parent object. Changes to the school data are seemingly ignored
Is there any way to achieve the kind of thing I want here?
Thanks,
This is probably similar to what I'm doing, although I'm not using Linq. I'm using a vanilla ObjectDataSource and displaying data in a drop down list via a different data source. Add a new Event for the FormView that is called during the "ItemUpdating" event. Embed code to directly save your changes in that event. Then as the FormView is saved, everything else is saved.
If you want it to be saved after the FormView, use the ItemUpdated event instead. It's a bit of a manual process, but it does get around the problem.

Resources