C# - Bind A Grid To An Anonymous LINQ Result, Then Commit Changes To DB?
Mar 4, 2011
I've been looking into how best to do this and wisdom would be appreciated. For read only purposes, I've been happily using LINQ and binding it to a grid. For editing purposes, I've used the LinqDataSource control, enabled the Edit/Delete operations in the process, and I have a nice editable grid bound to some or all of the table's fields.Now I have a situation where I want to edit a few fields in table A, but there are various values in linked table B that I want to display in that grid too (no editing of those). So my query looks like the below. The fields in tblDupes (cleared, notes) are what I want to edit, but I'd like to display those tblVoucher ones.
var theDupes = from d in db.tblDupes
where d.dupeGroup == Ref
select new
[code]...
A similar but different question LINQDataSource - Query Multiple Tables? sent me looking at scott Guthrie's blog entry 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, where he handles various events to have a LinqDataSource with a custom query across tables. This still seems aimed at explicitly designed classes though, even if the class has only a subset of the fields.
So my question is: is there an easy way to allow committing of the changes made to the anonymous collection (a changes.Submit type action), or just an easy way to 'display' fields from another table while not involving them in the updating?EDIT: Thinking more, it doesn't have to be anonymous really. I'd be happy to define a class to contain the elements in that query, since it won't change often. But, those elements would be across two tables, even though only one needs updating. Not sure if that suggests entity framework would be more suitable - I get the feeling it wouldn't - I don't want the whole 'model' always grouping the fields in this way.
View 1 Replies
Similar Messages:
Oct 14, 2010
i can assign a simple anonymous function and it works, but i'm having trouble with a more complex one.
i am attempting to disable an image button after it is pressed.
any alternatives would be welcome, but i think this is the recommended
[Code]....
View 2 Replies
Jul 1, 2010
I have this ListView that has a Drop Down List.Everything works fine (I think/hope) except that the drop down list are not showing its result correctly.This is the code.
Front-End
[Code]....
The code behind consist of the page_load and the ItemDataBound
[Code]....
View 3 Replies
Mar 1, 2011
I'm having a problem with my Linq to XML query. I'm getting the result data I want, but it's nested so deep that there must be a better way.Here is my XML:
[Code]....
I'm trying to get a list (simple string[]) of all Item IDs where Category Names contains "Other".Here is my Linq:
[Code]....
[Code]....
Here is a snapshot of my result from Visual Studio:The results I want are there ("item100", "item400", "item500"), but buried so deeply in the results var.
How can I get the query to return a simple
string[] = { "item100", "item400", "item500" }
View 4 Replies
Apr 23, 2010
In my gridview I have fields for inserting a new record in the footer.
In my objectdatasource selecting event if no records came back I bind a single mock row to force the footer to show so they can still add records. Since the row does not contain real data I hide the row.
[Code].....
View 3 Replies
Jun 30, 2010
Do any one know how to return an anonymous type. I am using Linq where i need to return the following code
private <What's the return type to be provided here> SampleLinq(Int32 Num)
{
var query = (from dept in obj.DeptTable where dept.Id == Num select new { dept.DeptName, dept.DeptId });
return (query)
}
View 8 Replies
Mar 25, 2011
I am consuming an RSS feed to display on my website using a repeater control. I was wondering if it's possible in VB to return an anonymous type from my linq query rather than a collection of strongly typed RSSItems. I know this is possible in C#, however haven't been able to work out a VB equivalent.
[Code]....
View 1 Replies
May 19, 2010
Problem in YUI:I am using YUI grid,my dataset contains some special character.i bind my dataset into the grid,but its not displayed in my grid? how to solve this
View 1 Replies
Jun 30, 2010
I'm getting some Xml back from a service. I would like it to be the datasource of a grid view on my aspx page. Here is a sample of the Xml
<?xml version="1.0" encoding="utf-16" ?>
<ArrayOfTripTollCompleteDC xmlns:xsi=[URL]"
xmlns:xsd=[URL]>
<TripTollCompleteDC>
<TripTollId>5</TripTollId>
<DMSLaneModeID xsi:nil="true" />
<HOVOnly>false</HOVOnly>
<CreateDateTime>2010-06-07T15:54:01.023</CreateDateTime>
<ConfigVTMSDelaySeconds>5</ConfigVTMSDelaySeconds>
</TripTollCompleteDC>
and here is my code that parses the xml and tries to bind the grid. What am I missing here?
var retVal = service.GetTripDetailsByTripID(tripId);
var xmlTrips = XDocument.Parse(retVal);
var tripTolls =
from t in xmlTrips.Elements("TripTollCompleteDC")
select new {
TripTollId = (int)t.Element("TripTollId")
, DMSLaneModeID = (int?)t.Element("DMSLaneModeID")
, HOVOnly = (bool)t.Element("HOVOnly")
, CreateDateTime = (DateTime)t.Element("CreateDateTime")
, ConfigVTMSDelaySeconds = (int)t.Element("ConfigVTMSDelaySeconds")
};
grdTripDetails.DataSource = tripTolls;
grdTripDetails.DataBind();
I realize these are anonymous types. Is that a problem? I have verified the service is returning the Xml as stated above. Can anyone out there point me in the right direction? Just for completeness, here is the grid markup <asp:GridView runat="server" ID="grdTripDetails" />
View 1 Replies
Feb 18, 2011
I cant bind my Grid. I dont know what I am doing wrong, the grid appears empty when I run the program.
here is my code ::
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
this.BindGrid(this.GridView1);
}......
View 2 Replies
Jan 18, 2010
I am currently implementing a client-side paging solution using ASP.NET, jQuery and JSON.
I have been following the excellent article from encosia: http://encosia.com/2008/08/20/easily-build-powerful-client-side-ajax-paging-using-jquery/
In my Web Method I retrieve my data from the database as a DataTable:
DataTable categoryProducts = ProductViewerAccess.GetCategoryProducts
("AA", 4, 0, Page.ToString(), out howManyPages, "FALSE", 0, "CostPrice", "asc", destinationList);
I then retrieve the data from the DataTable into an anonymous type:
var feeds =
from feed in categoryProducts.AsEnumerable()[code]....
This all works great.
However, I would like to extend the code to perform some evaluation checks (e.g., check that various columns in the DataTable are not NULL) and other pre-processing (e.g., call various functions to build the image URL based on the image ID - which is another column in the DataTable not shown in the code fragment) before I return the resulting rows of the DataTable as an anonymous type to the client-side.Basically, I want to iterate through the DataTable, perform the evaluation checks and pre-processing, while building my anonymous type manually as I go. Or maybe there is a better way to achieve this?
View 2 Replies
Mar 9, 2011
i have a sqldatasource which will return 1 field (1 row) for an ID. I need to get that result and display it on a textbox. I would do it using a stored procedure (this was already made) but i was thinking sqldatasource is easier. Is there a way to bind that result onto my textbox?
<asp:SqlDataSource ID="ds1" runat="server"
ConnectionString="<%$ ConnectionStrings:conn1%>"
ProviderName="<%$ Connectionstrings:conn1.ProviderName %>"
SelectCommand="sp_1"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="accountID" Type="Int32" />
<asp:Parameter Name="activitydate" Type="DateTime" Direction="Output" />
</SelectParameters>
</asp:SqlDataSource>
View 2 Replies
Oct 27, 2010
I need to bind an ASP.NET control something like so:
<asp:label ID="lblName" Text=<%# GetName()) %>
and in CodeBehind file I have this method:
protected string GetName()
{
...
}
Is this right, or how I can do something like this?
View 2 Replies
Jan 3, 2011
I have an ASP .NET web application. I'm fairly new to .Net but a longtime SQL and Java programmer. I have a requirement to implement a search feature as it is currently implemented in the legacy application. There is a pageable grid of data displayed and a search box. You type your search criteria and the grid pages to the first match. A "next match" button pages to the next item etc. This way the user sees where their search item falls in the hierarchy of the data. I have seen examples where the search criteria filters the data, limiting the data results.
View 1 Replies
Dec 8, 2010
How can I use Order by on the result of a LinQ to SQL query ?
I have the following Situation:
Dim ret As New Object
ret = From status In tableStatus _
Select status.STATUS_ID, _
Text = Function_GetText(status.TEXT_ID)
Now I have to order this result on the field Text, has anyone an idea? (I can't use in my case Orde by Function_GetText(status.TEXT_ID))
View 3 Replies
Dec 5, 2010
How to randomize a LINQ query result?
Below takes 4 of the records but it won't randomize in every request. [:(]
Dim products = (From p In Northwind _
Order By Guid.NewGuid _
Select New With { _
.Name = p.Name, _
})
Return products.Take(4).ToList()
View 7 Replies
Aug 18, 2010
i want take a single value result from linq query
if i have :[Code]....
the variable result does not return nothing, only tostring() and similar how can i get a single result from linq query and use it in my ID variable?
View 1 Replies
May 5, 2010
If I have a linq query that creates the anonymous type below:
select new
{
lf.id,
lf.name
lf.desc,
plf.childId
};
Is it possible to assign a specific type to one of the members? Specifically I would like to make lf.id a null-able int rather than an int...
View 2 Replies
Sep 27, 2010
How can I pass the result of the linq to a textbox?
Code:
string search = txtSearchPO.Text;
IPSBLL.TransactionInfo dbInfo = new IPSBLL.TransactionInfo();
var q = from info in dbInfo.GetTransactionInfo()
where info.PONumber == search
select info;
txtPONumber.Text = q;
I need to access the column data something like this:
Code:
DataTable.Rows[index].columnName
How can I do that in LINQ?
View 7 Replies
Mar 16, 2011
Here is my Controller:
public class MatchManagerController : Controller
{
//
// GET: /MatchManager/
public ActionResult Index()
{
return View();
}
public ActionResult CreateMatch()
{
return View();
}
}
Here is my View:
@model MatchGaming.Models.MatchModel
@{
ViewBag.Title = "CreateMatch";
}
CreateMatch
@using (Html.BeginForm()) {
@Html.ValidationSummary(true).....
I want my MatchTypeId to be a drop down that populates from my table MatchTypes.
View 1 Replies
Dec 9, 2010
New to Linq and Var type have a method where linq query is executed, want to return the result and assign it to GridView. but method don't take the return type as var.
So was wondering how do i return this query result?
Should i assign this result to DataTable first and make the method return type as DataTable?
Here is the code, This is what i want to do but not sure what is the right way
[Code]....
View 6 Replies
May 16, 2010
I drafted 2 ASP.NET applications using LINQ. One connects to MS SQL Server, another to some proprietary memory structure. Both applications work with tables of 3 int fields, having 500 000 records (the memory structure is identical to SQL Server table). The controls used are regular: GridView and ObjectDataSource.
In the applications I calculate the average time needed for each paging click processing.
LINQ + MS SQL application demands 0.1 sec per page change.
LINQ + Memory Structure demands 0.8 sec per page change.
This Is shocking result. Why the application handling data in memory works 8 times slower than the application using hard drive? Can anybody tell me why that happens?
View 2 Replies
Dec 21, 2010
How can i convert following sql guery to LINQ in C# ? I dont need all columns from both tables and the result set should be IEnumerable<DataRow>
select c.level,cl.name,c.quantity
from dbo.vw_categories c
left join dbo.vw_categoriesLocalization cl on c.level = cl.level and cl.language = 'en'
where c.level like '000%' and c.level <> '000';
View 2 Replies
Sep 4, 2010
when i found datareader object containing data after execution of query
simply giving gridviewdata=dr;
does not work
View 1 Replies
Jan 20, 2011
for example,
var result = from category in myEntities.Categories
where category.UserId == userId
orderby category.CategoryName
select category;
What is the type of "result"? I casted it to an IQueryable variable and it worked except it did not have some of the methods normally available, e.g. Count(). In my program I have to cast it to some explicit types and then use the Count() method.
View 3 Replies