How To Update List Using Lambda Expression

Mar 15, 2011

I have two lists. lst contains ViewState Data i.e All the records of the gridview & second lstRank contains the list of integer(i.e ID) for only those records which are marked as checked (i.e Gridview contains a columns for checkbox). Now i want to update the lst bool status depending upon integer ID of lstRank. How it can be achieved by lambda expression

List<Tuple<int, string, bool>> lst = (List<Tuple<int, string,bool>>)ViewState["gvData"];
List<int> lstRank = gvDetails.Rows.OfType<GridViewRow>().Where(s => ((CheckBox)s.FindControl("chkSelect")).Checked)
.Select(s => Convert.ToInt32(((Label)s.FindControl("lblRankCD")).Text)).ToList();

View 1 Replies


Similar Messages:

C# - How To Convert Lambda Expression Output To List

Mar 14, 2011

I am selecting the checked rows from Gridview. To achieve this i have written a lambda expression using dynamic keyword.

var dn = gvLoans.Rows.OfType<dynamic>().Where(s => s.FindControl("chkSelect").Checked == true).Select(s => s.FindControl("lblCD")).ToList();

I want the output of this in List. Can it be achieved by extending the query or i have to write foreach statement.

View 2 Replies

ADO.NET :: Does Lambda Have An IN Expression That Works Like Sql

Feb 6, 2011

I have a dictionary with integers representing ProductId's.

I want to get all the Products that are listed in this dictionary. What is the best way of doing this?

I have tried the following which doesnt work:

gvBasket.DataSource = ent.Products.Where(x => x.ProductId in Dic.Keys);

View 9 Replies

MVC :: RenderAction With Lambda Expression In MVC 3.0 Preview 1

Sep 29, 2010

i have the following, which works:

@{Html.RenderAction("Detail", "Help", new { pageName = "press" });}
But instead i'd like to use a lambda expression to get away from the string bits. I tried using the following (which is the nearest approximation i could figure based on my limited knowledge of the engine):

@{Html.RenderAction<HelpController>(x => x.Detail("press"));}
But i get the following error:

The non-generic method 'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, string, System.Web.Routing.RouteValueDictionary)' cannot be used with type arguments

However, i'm reading in the Apress MVC 2.0 book that it is in fact declared as a method that takes type arguments. Am i missing an assembly reference, or has it not been included in the MVC 3.0 Preview 1 build?

View 3 Replies

ADO.NET :: How To Create A Generic Lambda Expression

Oct 26, 2010

I Use entity framework 4.

Here is my model

Language
LangID
LangName
Product
PrdID
IsActive
ProductText
PrdID
LangID
Text
Category
CatID
IsActive
CategoryText
CatID
LangID
Text

Each time I want the text for one of these model, I execute this lambda expression p=> p.LangID == 1

Is it possible to create a generic lambda expression function that all of these model can use.?

View 1 Replies

Lambda Expression Is Slower Than Foreach Statement?

Mar 23, 2011

I did a small experiment to test whether lamdba expression can retrieve faster results than foreach statement. but, Lambda failed

[Code]....

why lambda is slower than foreach. This may be a drawback of lambda expression

View 3 Replies

C# - How To Use Lambda Expression To Select Different Fields From Field Names

Nov 18, 2010

I need to get two fields from a database table (retrieved using linq-to-sql), one field is a datetime (and is a fixed field) and the other is always a decimal, but the field can be different.

The table holds currency data which is processed twice a day and in different currencies so could have fields such as AM_USD, PM_USD, AM_EUR etc. And I need to get data such as a list of the date against PM_USD or the date against AM_EUR.

I would like to be able to call the data using a lambda expression for example (this is a stripped out example):

data = TableData.Select(x=>new {x.DateTimeAdded, x.[**field name as string**]});

I have been trying to write a function to do this, and am failing dismally.

The closest I have managed is:

private Func<TableData, KeyValuePair<DateTime, decimal>> CreateSelect(string FieldName)
{
var parameterExp = Expression.Parameter(typeof(TableData), "sel");
var dateParameter = Expression.Parameter(typeof(DateTime), "DateTimeAdded");
var fieldParameter = Expression.Parameter(typeof(decimal), FieldName);
ConstructorInfo constructorInfo = typeof(KeyValuePair<DateTime, decimal>).GetConstructor(new[] { typeof(DateTime), typeof(decimal) });
NewExpression constructExpression = Expression.New(constructorInfo, new ParameterExpression[] { dateParameter, fieldParameter});
var lambda = Expression.Lambda<Func<TableData, KeyValuePair<DateTime, decimal>>>( constructExpression, parameterExp);
return lambda.Compile();
}

Which fails with "System.InvalidOperationException: Lambda Parameter not in scope".

I'm sure I missing something obvious, or going about it wrong way.

View 2 Replies

ADO.NET :: Finding Lambda Expression Against Entity Framework Collection?

Aug 6, 2010

I'm new to LINQ and EF and I seem to be having trouble working this out.

I have a many-to-many relationship between my Location and Region tables. When adding or editing a Location, my interface allows the user to check any number of related Regions. If they click OK, I need to add any new relationships that were checked, and delete any existing relationships that have been unchecked. My basic code is shown below.

However, this code doesn't work. Lower down, the line location.Regions.Contains(region) returns false even when the location already is related to the region. The issue appears to be because the region is from my populated listbox that was initialized earlier and is no longer part of the current EF context. But if I try and add it, I get an error that there is already a Region with that ID.

It seems like what I want to do is change this line to something like location.Regions.Contains((r) => r.RgnID == region.RgnID) so I'm only testing for a particular ID. But this gives me the error "Cannot convert lambda expression to type 'TrailCalendar.Region' because it is not a delegate type."

I don't understand this error but, either way, I'm not sure how I can test if the relationship already exists without reloading a bunch of data, which I'd like to avoid.

View 1 Replies

C# - Pass Parameters To LINQ To XML Query By Using Lambda Expression?

Aug 17, 2010

I am new to LINQ to XML in .net(C#, asp.net). I want to know more about Lambda expressions. I am using Lambada expression with the following query.

count = FieldRoot.Element("USER").Element("MM")
.Descendants("MMMS")
.Where(a => a.Attribute("ID").Value == MID)
.SelectMany(b => b.Descendants("ABC")).Count();

how the Lambda expression work specially in case of parameters (in the above case a & b) ? What is the basic concept of parameters in Lambda expression ? Can we use the names of the variables defined outside of the query instead of a & b ? which elements a & b represent in the above case represent ? Can we pass parameters from outside in the query ? If we can pass parameters from outside query then how it will be done? If you give me any other example instead of the above query to understand the concept of parameter in Lambda expression.

View 1 Replies

DataSource Controls :: Equivalent Of Group Join In Lambda Expression?

Jun 29, 2010

What will be the equivalent GroupJoin lambda expression in LINQ when I do this.

Dim fruit_salad = (From fruits In _DataContext_Fruits _
Group Join fruitRipe In _DataContext_FruitRipe On fruitRipe.fID Equals fruits.fID Into Group
From fruitty_lecious In Group.DefaultIfEmpty() _

[code]...

View 5 Replies

C# - Lambda Syntax To Remove Rows From List?

Feb 5, 2011

Given:

string removeRows = "";
int i = 0;
foreach (var row in userStats)
{
if (row.OrderRow.RegistrationType == "Want Removed")
{
removeRows = removeRows + i.ToString() + ",";
}
i++;
}

what's the Lambda syntax to execute the removal?

View 1 Replies

C# - Searching In Side An Object's List Of Objects Using Lambda Expressions?

Jan 28, 2010

I have 2 tables; they have a many-to-many relationship. One is called Blog the other is Tag.

A Blog can contain a List of Tag objects. How can I go about getting all blogs that have a passed in tag name using lambda expressions?

View 1 Replies

C# - Error - "Cannot Convert Lambda Expression To Type 'string' Because It Is Not A Delegate Type"

Jun 12, 2010

I get this error: "Cannot convert lambda expression to type 'string' because it is not a delegate type" - keyword select become underlined in blue.

[code]....

Above code should displays drop list of employees first name and last name in a combo box

View 2 Replies

C# - Linq Expression To Return A List Of Strings Based On Field Count?

Nov 11, 2010

Say I have a table Comments with these columns: Id, Comment, Category, CreatedDate, CommenterIdI want to get the top 5 categories from the Comments table (based on the count of each category in that table). How can I do this in linq, to return either List or IQueryable?

View 2 Replies

Visual Studio :: Add Values To Standard Expressions List In Regular Expression Editor Dialog

Apr 25, 2010

In the "Regular Expression Editor" dialog in VS 2008 ( or 2005 for this matter ) ,

there is a list of "standard expressions" like :

"French phone number" , "French postal code" etc..

And of course there is an option to select a "Custom" and then enter your own regular expression.

Well.. I want to add a predefined expressions to that list . Like : "Israeli phone number" .

I don't want to enter it every time by selecting a custom value .

I want my developers in the team available items for them to choose.

Anyone knows how to alter that list ?

I've found some question about it on the web - and the answer given is that it's not possible .

View 1 Replies

Web Forms :: Regular Expression - Make BBCode - Translation From Textarea - Stuck On Translate List To Html

Jun 18, 2010

Im trying to make some BBCode-translation from textarea, but im stuck on translate list to html. I have this fo Bold text:

[Code]....

But how can i do if i want to translate this:

[Code]....

View 1 Replies

Lambda Check For Null?

Mar 29, 2011

var pq = attributes.SingleOrDefault(a => a.AttributeName == PasswordQuestion").AttributeValue;

The above code will throw an error if null. What is the best way to handle this?The below code would work, but I can't help but feel there's a more graceful way?

var pq = (attributes.SingleOrDefault(a => a.AttributeName == "PasswordQuestion") != null) ? attributes.SingleOrDefault(a => a.AttributeName == "PasswordQuestion").AttributeValue : null;

View 1 Replies

Web Forms :: Inline Expression Or Binding Expression In The Server Head Section?

Aug 25, 2010

I write inline expression and binding expression in the server head section:

[Code]....

[Code]....

But both kinds of expression aren't parsed or executed except the ResovleUrl menthod. The html renders like this:

<head><link rel="stylesheet" type="text/css" href="<%= Request.ApplicationPath %>themes/style1.css" /><link rel="stylesheet" type="text/css" href="<%# Request.ApplicationPath %>themes/style2.css" />
<link rel="stylesheet" type="text/css" href="/themes/style3.css" />
<script type="text/javascript" src="/js/jwork.js"></script>
</head>

As I know, the inline expression in the attributes of server control can't be parsed but the binding expression should if we invoke the DataBind method. But the above case breaks the rule.

View 5 Replies

Web Forms :: Regular Expression Validator / Add Wording To Current Expression:  W+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*?

Feb 16, 2010

I'm trying to use the validator to work on a email form to ensure that they enter a valid from email address. That part works. I also want to add to the expression the text that I pre-populate in the txtbox ("Enter your email address") so on postback, after sending the message, I can clear the fields and repopulate that box.

How do I add that wording to the current expression: w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*

View 4 Replies

MVC :: Strongly-Typed HTMLhelper Lambda Syntax Limitations?

Jul 13, 2010

Just wanted to get clarification that methods like HTML.TextBoxFor() exist ONLY for the benefit of compile-time parameter type checking.

From my experimentation, these appear to ONLY accept a simple "expression lambda" syntax, which simply provides reference to a member property, and will not allow more robust use of "statement lambda" syntax. Other places in the .NET framework where lambda's are used, "statement lambda" syntax can be used, such as :

( x => { x += 7; if(x < 9) return x * 3; } )

... in effect, multiple statements of "in-line" code.

The type checking benefit is great - I just wanted to understand if there is additional capability which I have not recognized.

View 1 Replies

Web Forms :: Validation Expression For Regular Expression Validator?

Feb 2, 2011

I am using Regular Expression validator for a text box. The below is working fine.It is not performing validation when I enter values like 0000..001.How can I modify validation expression? But it would allow values like 100,...5000 i.e zeros after a number.

<asp:RegularExpressionValidator ID="reg2" runat="server" ControlToValidate="rng2"
ValidationExpression="^[0-9]+" ErrorMessage="*Please Enter a Valid Number for Second Range."
ForeColor="Red" Font-Bold="True"></asp:RegularExpressionValidator>

View 2 Replies

C# - Visual Studio Immediate Window - Lambda Expressions Aren't Allowed?

Dec 10, 2010

I'm debugging some tricky generic List-based code in VS 2010 - lots of heirarchy-processing etc.. Of course lambda expressions and anonymous methods aren't permitted within the immediates window and I can't be doing with stepping thru the code in the usual way as I'm still trying to get my head around the hierarchies ...Can anyone suggest a workaround or an alternative tool?P.S. An aside - I can't seem to find a visual studio 2010 tag?

View 1 Replies

Regex - Regular Expression And Validation Expression ?

Dec 1, 2010

I need some help in regular expression.I am validating the textbox text when updating the records.When i click the update button,the first 5 letters should be equal to CM000 or cm000.How to validate this using regular expression in asp.net. does anyone know validationexpression for this.

View 1 Replies

MVC :: Indicate To The Model Binder That Want To Update The List

Apr 17, 2010

I have a control that's bound to a list property. If I remove elements from that list using javascript and post, then the model gets updated, and the elements get removed.

Unless I remove all the items from the list. Then no names for that property go into the form data, and so the default model binder leaves the model's list untouched. This code from DefaultModelBinder.cs line 572 in the RTM sources makes it clear:

[Code]....

So how do I indicate to the model binder that I do want it to update the list and Ido want the list to be emptied?

View 3 Replies

MVC :: Update A Dropdown List In 2 RC 2 View

Mar 9, 2010

I was trying to implement a dynamic update of a dropdown list in an ASP.NET.MVC2 RC 2 view. My code didn't work. So, in order to verify my approach, I resorted to a published code, which supposedly should be correct: In the View:

<%= Html.DropDownList("Numbers",(IEnumerable<SelectListItem>)ViewData["Services"]) %>
<select id="Select1">
</select>
<input type="button" id="Button1" value="Fill By Array" />
<script language="javascript" type="text/javascript">
$(function() {
$("#Button1").click(function(e) {
e.preventDefault();
var data = [];
$.getJSON("/Home/GetListViaJson", null, function(data) {
data = $.map(data, function(item, a) {
return "<option value=" + item.Value + ">" + item.Text + "</option>";
});
$("#Select1").html(data.join(""));
});
});
});
</script>
In the Controller:
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
//ViewData["Message"] = "Welcome to ASP.NET MVC!";
ViewData["Numbers"] = GenerateNumbers();
return View("Index");
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetListViaJson()
{
return Json(GenerateNumbers());
}
private static List<SelectListItem> GenerateNumbers()
{
var numbers = (from p in Enumerable.Range(0, 20)
select new SelectListItem
{
Text = p.ToString(),
Value = p.ToString()
});
return numbers.ToList();
}
public ActionResult About()
{
return View();
}
}

The Html.DropDownList was correctly populated on PageLoad() event. But the GetListViaJson() action method, when called on the button event, did not update the "Select1" element. how to solve this update problem.

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved