ADO.NET :: Getting Subset Of A List Using_LINQ?
Nov 16, 2010
i have a list 1,2,3,4,5,6,7 and the batch size is 2.batch size 2 means for every 2 numbers i need to call a functionsomething like "1,2" "3,4" "5,6" "7"is there a nice way to do this in Linq C#
while()
{
var templist = mainlist.getelementsFrom(0,2);;
pass templist to another block
update indexes so that next time the line would be templist = mainlist.getelementsfrom(3,5)
}
View 2 Replies
Similar Messages:
Jan 17, 2010
By picking MVC for developing our new site, I find myself in the midst of "best practices" being developed around me in apparent real time. Two weeks ago, NerdDinner was my guide but with the development of MVC 2, even it seems outdated. It's an thrilling experience and I feel privileged to be in close contact with intelligent programmers daily. Right now I've stumbled upon an issue I can't seem to get a straight answer on - from all the blogs anyway - and I'd like to get some insight from the community. It's about Editing (read: Edit action). The bulk of material out there, tutorials and blogs, deal with creating and view the model.
So while this question may not spell out a question, I hope to get some discussion going, contributing to my decision about the path of development I'm to take. My model represents a user with several fields like name, address and email. All the names, in fact, on field each for first name, last name and middle name. The Details view displays all these fields but you can change only one set of fields at a time, for instance, your names. The user expands a form while the other fields are still visible above and below. So the form that is posted back contains a subset of the fields representing the model. While this is appealing to us and our layout concerns, for various reasons, it is to be shunned by serious MVC-developers.
I've been reading about some patterns and best practices and it seems that this is not in key with the paradigm of viewmodel == view. Or have I got it wrong? Anyway, NerdDinner dictates using FormCollection och UpdateModel. All the null fields are happily ignored. Since then, the MVC-community has abandoned this approach to such a degree that a bug in MVC 2 was not discovered. UpdateModel does not work without a complete model in your formcollection. The view model pattern receiving most praise seems to be Dedicated view model that contains a custom view model entity and is the only one that my design issue could be made compatible with.
It entails a tedious amount of mapping, albeit lightened by the use of AutoMapper and the ideas of Jimmy Bogard, that may or may not be worthwhile. He also proposes a 1:1 relationship between view and view model. In keeping with these design paradigms, I am to create a view and associated view for each of my expanding sets of fields. The view models would each be nearly identical, differing only in the fields which are read-only, the views also containing much repeated markup. This seems absurd to me. In future I may want to be able to display two, more or all sets of fields open simultaneously.
View 5 Replies
Jan 16, 2010
My classes look something like this (I include only the relevant properties):
public class Order
{
public virtual Customer Customer { get; set; }
public virtual IEnumerable<OrderLine> OrderLines { get; set; }
}
public class OrderLine
{
public virtual string Product { get; set; } // Simplified
}
Now I What I want is to create a detached criteria that selects all orders for a given customer, and at the same time retrieves only the first 10 OrderLines for each order. The first part is easy:
Customer someCustomerObject = ...; var criteria = DetachedCriteria.For<Order> ).Add(Restrictions.Eq("Customer", someCustomerObject);
But how do I instruct NHibernate to retrieve eagerly the first 10 orderlines for each order retrieved by the criteria above?
I've tried using a Filter based on the following example (taken from Nhibernate documentation):
session.CreateFilter( lazyCollection, "").SetFirstResult(0).SetMaxResults(10).List();
But when I give Order.OrderLines to the CreateFilter method, it retrieves all orderlines first, and then afterwards retrieves the 10 first orderlines, which is not what I want. I also tried combining this with a call to NHibernateUtil.Initialize to no avail.
How do I create a detached criteria for this problem? Or, if that is not entirely possible, how to I retrieve, for each order, the 10 first results only, without fetching the entire collection?
View 1 Replies
Aug 9, 2010
I'm using RegularExpressionValidator controls to impose password rules when creating new passwords. I want to avoid repeatitons such as 'aaaa' or sequences such as '12345' in the password.
How do I write the validationexpression to a RegularExpressionValidator to impose this rule? I do not want to do thing using C#, just with a regular expression that could be put within the validator control like below:
<asp:RegularExpressionValidator
ID="RegularExpressionValidator3"
runat="server"
ErrorMessage="Password
should contain Minimum 8 Characters"
ControlToValidate="txtPwd"
ValidationExpression="w{8,30}"><asp:RegularExpressionValidator>
View 7 Replies
Jan 25, 2010
how to export only a subset of columns from Gridview to excel? i'm sure there are examples online, but have not been able to get the right kinda examples.
View 1 Replies
Oct 8, 2010
I am playing about just now trying to teach myself a little bit about the entity framework. I have a Gridview data bound to a Entity Date Source using the Entity Framework. If I select certain items in that list I then wish to redirect another page and populate another gridview with just the items selected (but with more detail, different includes/navigation properties)
This is probably the most simple thing but I have spent 2 hours banging my head on the wall trying to get this to work. Essentially I have a continue button which when clicked should identify all the UIDs (a column in the gridview) of the rows and allow me to subset to just these rows and pass them to another page to be rebound to another datagrid
View 2 Replies
Jul 2, 2010
I have a datatable with 17 columns and a bunch of data. I wnat a datatable with only 6 of the columns and the data for those 6 columns. So I need a subset of the original datatable. How do I loop through the original datatable with 17 columns and end up with a datatable with only the 6 columns I want with the corresponding data for those 6 columns?
View 4 Replies
Nov 10, 2010
How can i generate dropdown lists based on what has been selected in the checckbox list. Below is an example of what i need. if the user selects the options day, lotID and waferID, then 3 cascading dropdown lists should be displayed. And then a gridview displays data based on what has been chosen in the dropdown lists.
Day
LotID
SlotID
WaferID
VendorID
ToolID
LocationDetected
ProcessStep
Stage
Precipe
WaferStartMaterial
WaferStartVendor
WaferStartLot
WaferDiameterCOA
WaferMapTitle
BreakPoint
BreakpointSide
BreakpointMeasurement
View 3 Replies
Jun 24, 2010
I have drop down list box that I would like to show two columns, is this possible? Or can it be done with a list box?The query correctly retrieves all of the table data to be displayed, one colum is an abbreviation, the other a bit longer description.
View 2 Replies
May 27, 2010
I have a situation where I want to show the selected records out of total records for a product of an employee
1) There is a checkbox list bind to <List> of objects from object datasource (For total items in list)
2) Now I want to check the selected items for a particular record in this list
3) For this purpose I have another list of <List> selected items returned by data access layer (For selected items for that employee )
4) How do I bind the selected objects with the total items list ?
5) In spaghetti coding model it was all too easy just by binding the checkbox list with a sql data source and running a for each on form load
View 5 Replies
Sep 16, 2010
Just wondering how to implement a user's list into website ? im using ASP.NET C#. I want to be able to:
add/delete usersadd/remove roles
View 2 Replies
Feb 17, 2010
Clicking the label of a drop down list, re-sets the selected value to the first item in the list. This has a history of causing data entry problems when users accidently click on the label.
In the below example ddlContactType has a selected value as 'PRIMARY' and whenever i click on the lblContactType Text, the dropdown box Selected value is changing to "Select One" Text.
How to prevent this one. It should be on PRIMARY Only.
<p>
<tr> <td ><asp:Label ID="lblContactType" Font-Bold="true" Text="Contract Type: *" ForeColor= "red" runat="server" AssociatedControlID="ddlContactType"></asp:Label> </td> <td > <asp:DropDownList runat="server" ID="ddlContactType" DataSourceID="SqlDataSource2" AppendDataBoundItems="true"
DataTextField="TYPE" DataValueField="ID" SelectedValue='<%# Bind("CONTACT_TYPE_ID") %>'>
<asp:ListItem Text="Select One" Value="0" Selected="True"></asp:ListItem>.......
View 4 Replies
Jan 17, 2011
I have a databound dropdownlist and have a problem with the default value it selects.When I attempt to edit a record the dropdownlist shows the first value in the list rather than the current value. I want the dropdown list to display the current value.
I'm sure this is very simple but I'm very new to ASP.NET.
I'm using .NET version 4.
View 4 Replies
Feb 6, 2010
I have the following Students class:
[Code]....
I need the 1 since it's a foreign key in another table. For the life of me, I can't get this to work like this.
View 7 Replies
Mar 18, 2011
I'm trying to progam a strongly typed "Create" view using MVC 3 and razor. I want the user to be able to select a customer from a dropdown list (I populated this from my database using ViewBag in the controller). When the user has selected a customer I want a separate dropdown list to generate a list of dogs belonging to that customer related by the customerID in the database. The create button on the form will then take both of these values along with the the other fields and save it to the database.
View 1 Replies
Nov 10, 2010
I have a requirement in my application that, while saving the application, need to get all the value from drop down list and pass it to the view model. But application should not allow the user to select more than one item from drop down list manually, ie, only one value at a time. My view model is like ...
public class ListManagement
{
public IEnumerable<selectListItem> InactiveProduct { get; set; }
public string[] InactiveProductSelected { get; set; }
public IEnumerable<selectListItem> ActiveProduct { get; set; }
}
[code]...
View 3 Replies
Oct 21, 2010
1 My DataTable Return following Data
Acct Books Annual
Acct Books Monthly
Acct Tax Income Tax
Admin GH Eqpt
Admin Offc Eqpt
Admin Offc Misc
Admin Offc Eqpt
[code]...
View 10 Replies
Nov 5, 2010
I am using a strongly-typed view to display a list of products, where every li-element gets a unique id:
<ul id="product-list">
<% foreach (var item in Model.Products)
{ %>
<li <%= "id="product_" + item.Id + """ %> >
<div class="item">
<%= item.Name %>
</div>
</li>
<% } %>
</ul>
Now I want to attach to the click-event of every single li-element, so that if the user clicks on a div-element, detailed product-informationen should be loaded asynchronously into a details-pane. I know how I can use jQuery to invoke an action-method ajax-style and also how to display the json-result which contains the product-details, BUT I have no idea, how I could attach the onclick-event to every single div, so that I can use the productId to load the details.
View 4 Replies
Dec 1, 2010
How would I create a list then on click add data to the list which is then stored into a session variable, then on another page retrieve the variable and output them? Currently I have:
Page Load:
List <myClass> listName=new List<myClass>
OnClick:
listName.add(3);
listName.add(4);
Session["IDs"]=listName;
Second Page
I need to get the whole list and add output the list so I can output (hopefully) the '3' and '4'.
View 1 Replies
Oct 17, 2012
Is it possible to set tab index value for list items of ASP.Net RadioButtonList control.
View 1 Replies
Aug 20, 2010
I have a Cascading drop down list that is working fine to load the correct lists however I would like to have the last one initiate a query and display a datagrid on the same page containing the results of the query. Without Ajax involved this seems rather easy by using autopostback on the drop downs. If I could do it through Ajax that would be great but I can settle with having the page to reload to display the data. Right now I'm not sure how to do either. I enabled autopostback on the last drop down and wrote a method for it but I get an error at runtime saying:
Invalid postback or callback argument
View 4 Replies
Mar 7, 2011
I have string which came from the database,now i want to compare each charater of the string with the radiobuttonlist value and check box list value and select both radiobutton list and checkboxlist.
Here i write down some code but its just select 2 item of the each radiobuttonlist and checked all checkboxlist.
[Code]....
View 2 Replies
Mar 25, 2010
I have a master page which has an unordered list in this way:
[code]....
These links are directed to my content pages. I am able to highligt the selected list item on hover and on active.
But I do not understand how I can highlight the selected list item as long as the user is on that specific page/link (current list item). I know that we can specify a seperate body tag and id for each of the content pages and then use CSS to highlight the current list item, but all this code rests already inside a body tag in the master page.
View 7 Replies
Feb 24, 2010
I'm designing my own custom control that contains a .NET dropdownlist. What I'm wondering is if it is possible to populate my dropdownlist with listitems placed in a placeholder? For example:
<asp:DropDownList ID="ddlFilter" runat="server" >
<asp:PlaceHolder ID="ListItemPlaceholder" runat="server"/>
</asp:DropDownList>
This doesn't work because the DropDownList control only allows ListItems as child controls. But, I want to do something similar to this so when the user includes my control on a page, they can do something like this:
<mytag:MyControl Mode="DropDown" runat="server">
<ListItemTemplate>
<asp:ListItem Text="C" Value="c"></asp:ListItem>
<asp:ListItem Text="E" Value="e"></asp:ListItem>
<asp:ListItem Text="B" Value="b"></asp:ListItem>
</ListItemTemplate>
</myTag:MyControl>
I know I can do this by dynamically adding the ListItems in the page code behind, but I'd like to avoid that if possible.
View 1 Replies
Mar 25, 2011
I am getting this error yet I know it to be untrue.This is the code:
ddlPartnerOrganisation.DataSource = agency.AgencyGetListOfEYDN();
string temp = ddlPartnerOrganisation.SelectedValue.ToString();
ddlPartnerOrganisation.DataValueField = "AgencyID"
;
ddlPartnerOrganisation.DataTextField = "AgencyName"
;
ddlPartnerOrganisation.DataBind();
View 4 Replies