C# - Populating List Within A For Each Loop After Pattern Matching

Jan 15, 2010

I am trying to assign values I've gathered from a JSON feed to my own type, a class in which I have defined certain fields (properties) to put the JSON elements into, plus elements that are derived from a RegEx pattern matching process. This will then allow me to access the object using LINQ, as I am using a List to hold my objects. There is a foreach loop in my code that loops for each match that my RegEx method finds. I am only interested in the parts of the JSON feed where there is a match. So my own defined class is as such:

//simple field definition class
public class TwitterCollection
{
public string origURL { get; set; }
public string txtDesc { get; set; }
public string imgURL { get; set; }
public string userName { get; set; }
public string createdAt { get; set; }
}

And then I want to populate List in the RegEx Matches loop:

foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
var tc = new List<TwitterCollection>()
{
origURL = groups[0].Value.ToString(),
txtDesc = res.text,
imgUrl = res.profile_image_url,
userName = res.from_user_id,
createdAt = res.created_at,
};
}

The code will then go on to extract and sort the results via Linq to Objects. But compiler won't actually let me create my var tc = new List<TwitterCollection>() because: 'System.Collections.Generic.List' does not contain a definition for 'origURL' ... even though I have defined it. It does not flag an error if I simply write new TwitterCollection but then how do I refer to this in my Linq expression later on??

View 3 Replies


Similar Messages:

How To Use Regex To Find A Matching String Pattern And Delete It

Feb 4, 2011

I have a table Books with columns BookID, BookSummary, BookAuthor.

What I have stupidly done was to add a link to another url at the end of the BookSummary. Assuming the text is something like this:

This is a book about a love story in World War 2 in Europe. The book is written by Elliot James.

I have added

<a href='http=://XXXXXX'>Buy Book</a> at the end of the text making the final content of BookSummary to be like:

This is a book about a love story in World War 2 in Europe. The book is written by Elliot James.

<a href='http=://XXXXXX'>Buy Book</a>

I now need to write a code (via regex?) to read through each BookSummary, find the <a href='http://XXXXX'>Buy Book</a> and delete it. But the problem is the content in XXX could be anything and I cannot use typical string functions. Can anyone guide me to
achieve this using Regex?

View 7 Replies

How To Find Matching Values In A Generic List

May 25, 2010

I have anywhere from 5 to 10 generic list in an ASP.NET VB.NET web app. I would like to write a method to pass them all into, and return only the elements they all have in common.

View 2 Replies

Populating A Dropdown List Based On Value Selected In Previous List (mvc3)

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

MVC :: Proper Pattern For List Of Reusable Controls?

Aug 26, 2010

Say you have a for loop which renders a bunch of the exact same control. This is probably done with RenderAction or RenderPartial.

What is a way to ensure that each of these controls in the list gets wrapped in a div with a unique ID?

View 2 Replies

Populating A Drop Down List Using AJAX?

Mar 7, 2011

I have 3 drop down boxes, created using the HTML select tag. On page load, the first box has a few names. Now, when I click on one of the names in the first box, some more names should appear in the second and when I click on a name in the second box, some more names should appear in the third box. How can I achieve this using AJAX? I have to use ASP.Net and MS SQL Server only. I'm a complete noob to AJAX and I've been educating myself about it, but nothing's working out. I've been looking for the code for close to a week. I looked up w3schools.com, but when I tried that code, it didn't work. Please help me out and please tell me step by step, the things required in order to make it work, and what goes where. I have a deadline that is fast approaching and am at my wit's end trying to make it work.

View 1 Replies

Populating A DropDown List With Multiple Items?

Apr 30, 2010

I am running into some additional difficulties with dropdown lists, and I'm hoping you can correct my thinking.

I have a table populated with items; ITEM_ID, ITEM_NAME, ITEM_COST.

Here is my code:

[Code]....

With this code I get this error: DataBinding: 'ITEM' does not contain a property with the name '2'.

If I remove the assignment of DataSource to c1, the dropdown generates this error: 'DropDownList3' has a SelectedValue which is invalid because it does not exist in the list of items.

Parameter name: value

How should I code this so that the user is presented with a list of ITEM_NAMES, and that the ITEM_ID is stored in the value field so I can use it when the selection event is fired? I know I could databind the source directly to the dropdown list, but I am trying to understand the behind the scenes working of a dropdown list object.

View 5 Replies

Web Forms :: How To Use SelectedIndex On DDL Items After Re-populating List

Jun 23, 2010

I have a Drop Down List that has some items in it, I have a switch set up that will clear and repopulate the drop down list from a sql server db depending on which item is chosen. When the list is repopulated from a database table I want to use an if statement to do something based on which item is chosen. I've tried to use an if statement but no matter what I try, the code checks the if statement for the original items in the drop down list, not the items that repopulated the drop down list.

View 4 Replies

Jquery - Populating A Select List From An Autocomplete?

Sep 27, 2010

selecting a few items from a list of thousands. I have an autocomplete field that searches the db, and returns a name/id pair. This is working fine.

The next step is to preserve the selected IDs, and allow the user to remove some if needed. For this, I've been looking at using a select, and was hoping a UI something like that provided by this, but it doesn't work: it allows you to select items that already exist in the select, but doesn't work with a dynamically created select.

The final step is a traditional postback (using a submit button, this is in asp.net webforms) where I'll need to have access to the final list of IDs.

View 1 Replies

C# - Populating Dropdown List With Enum Using Reflection?

Mar 29, 2011

I am populating a page with controls reading properties of a class using reflection. If the property type is 'String' I will add a text-box. If the property type is enum I am adding a dropdownlist. Now I have to populate the dropdown options with enums. How can this be done?

Both the enum definition class(Assignment) and the class(classOne) using which I am populating the page with controls are in the same Namespace(MySolution.Data). While looping through classOne properties when the property name is 'SkillLevel' I will have to go to assignment class get the members of enum SkillLevelEnum and populate the dropdown.

Same needs to be done for other dropdowns also.

My Code:

namespace MySolution.Data
{
public class classOne : MyAdapter
{
private string _Model;

[code]....

View 4 Replies

Web Forms :: Populating Dropdown List To Show Many Integers

Mar 19, 2010

I want to populate a Dropdown list from divisons of a figure in my projects database

for example database figure 50

I want the dropdown list to show 5,10,15,20,25,30,35,40,45,50

The database figure wont always be the same.

how would i go about doing this ? esp the populating of the dropdown list itself based on the way i want to show it.

View 3 Replies

Update Panel - Populating Dropdown List From Database

Mar 25, 2011

I have a ASP.NET AJAX Autocomplete Textbox and Two other dropdownlist in a Update Panel. On selection of an item in Autocomplete Textbox, I want to populate Dropdown list from Database.

View 1 Replies

Populating DataKeyNames When Binding Generic List To Gridview

Feb 15, 2010

I have a generic List which is populated with an object which has properties like FirstName, Surname etc.

If I bind a gridview to the list with autocompletecolumns = true, the Gridview displays the data in the List.

The code looks like:

[code]....

My question is:

How do I populate the DataKeyNames with the properties (FirstName, Surname) contained in the object that is contained in each element of the Generic List?

View 4 Replies

Web Forms :: Populating A Ordered List In A User Control?

Jul 20, 2010

I have a upload section on a user control

<div class="AttachQuote"><fieldset>
<legend>Quote(s)</legend>
<asp:Button ID="btnAttachQuote" UseSubmitBehavior="false" Text="Attach Quote" runat="server" />
<ol id="olUploadedFiles" style="list-style-type: decimal; padding-left: 30px;">
</ol></fieldset></div>

the btnAttachQuote is defined as

protected global::System.Web.UI.WebControls.Button btnAttachQuote;

can i do something simular to olUploadedFiles? there are alot of list options in webcontrols and i'm unsure how to use them. I would like to use a for loop to populate olUploadedFiles from a string array in my .cs. something like ...

int i = 0;
while (files[i].Length !=0)
{
olUploadedFiles.add (files[i]);//i'll substring the file names out
i++;
}

I'm using the same control for both the form submit and the status page(label only mode). I can load the rest of the info i just can't populate the dropdown from the codebehind.

View 3 Replies

Web Forms :: Populating A Drop Down List With Sql Server Data?

Apr 7, 2010

I'm trying to retrive data from an SQL server db and populate one of the columns into a drop down list.

View 7 Replies

Pattern For Retrieving Complex Object Graphs With Repository Pattern With Entity Framework

Oct 13, 2010

We have an ASP.NET MVC site that uses Entity Framework abstractions with Repository and UnitOfWork patterns. What I'm wondering is how others have implemented navigation of complex object graphs with these patterns. Let me give an example from one of our controllers:

[code]....

It's a registration process and pretty much everything hangs off the POCO class Person. In this case we're caching the person through the registration process. I've now started implementing the latter part of the registration process which requires access to data deeper in the object graph. Specifically DPA data which hangs off Legal inside Country.

The code above is just mapping out the model information into a simpler format for the ViewModel. My question is do you consider this fairly deep navigation of the graph good practice or would you abstract out the retrieval of the objects further down the graph into repositories?

View 2 Replies

MVC :: AsyncController Gripes / Working Pattern For Converting A GET-POST-GET Pattern To Asny?

Feb 23, 2010

Does anyone have a working pattern for converting a GET-POST-GET pattern to asny?

I'm encountering the following issues:

1. You cannot mix Sync and Async action methods SubmitForm(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() ... (because the resolver gets all confused ... it doesn't use the HTTP verb to decide who to target. BTW: I think that's poor design, or a bug)

2. Renaming the get method name to something else eg: SubmitFormConfirmation(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() would be very awkward if it works ... because you have to doctor the <form markup to specify an action name.

3. You cannot give them all async names SubmitFormAsync(), SubmitFormAsync(bool? confirm), submitFormCompleted(), because the call just keeps malfunctioning. It sometime even behaves as if you are requesting a delete of something.

Can someone give an insight from an actually working sample.

View 5 Replies

Forms Data Controls :: Populating Drop Down List Manually?

Jan 27, 2011

what the problem is that i want to populate drop down list manually

but the thing is i have 3 drop down lists

in first one user will select table name from where the data of 2nd Drop Down list will come

suppose user selected seo then the sql query would be select project_name from dropdownlist1.selecteditem

and this query will show project_name column of seo table in dropdownlist2

then user will select any project name from dropdownlist2 suppose he select salveo so i want that my text box will get populate with project_id of project_name

suppose the project_id of salveo is 123 then automatically in textbox it will enter 123

View 26 Replies

.net Mvc Converting List<> So To Loop?

Dec 9, 2010

I am using this

List<JobsMeta> JobsMeta= _db.JobsMetas.Where(m => m.int_OrganizationId == null || m.int_OrganizationId == OrganizationInfo.OrganizationId).OrderBy(m => m.int_SortId).ToList();
ViewData["JobMeta"] = JobsMeta;

now using the view i want to loop through ViewData["JobMeta"]

<% foreach (var JobsMeta in ViewData["JobMeta"]))

View 1 Replies

Loop Through A Checkbox List?

Jul 15, 2010

I am building a checkbox lists:

<asp:CheckBoxList ID="CheckBoxes" DataTextField="Value" DataValueField="Key" runat="server"></asp:CheckBoxList>

And trying to get the value's of the selected items:

List<Guid> things = new List<Guid>();
foreach (ListItem item in this.CheckBoxes.Items)
{
if (item.Selected)
things.Add(item.Value);
}
}

I get the errror

"The best overloaded method match for 'System.Collections.Generic.List.Add(System.Guid)' has some invalid arguments "

View 3 Replies

Best Design Pattern For Associating Subdomain With Area And PRG Pattern?

Aug 21, 2010

Now that the next version of ASP.NET MVC is being prototyped and previewed (ASP.NET MVC 3 Preview 1 came out a couple of weeks ago), I wonder if we should call the attention of the Core Dev team (S Hanselman, Phil Haack and all) to this "feature."there a easy/non tacky way of associating subdomains &#8594; areas?Something like:
[URL]Also, whats the best accepted design pattern in implementing PRG pattern in ASP.NET MVC? I guess it should also get some official loving in MVC 3.

View 2 Replies

Web Forms :: Populating A Text Box With Data From DropDown List On Page Load?

Mar 9, 2011

I have a dropdown control that has a list of names in it called PlayerNameDropDownList_Insert and a textBox called PlayerName.

When I select a name from the dropdown it populates the textbox correctly.However, when the page opens the first name is selected in the dropdown but nothing in the textbox. How can I get the textbox to populate with the value of the dropdown at pageload?

[Code]....

View 4 Replies

DataSource Controls :: Populating Table Column Names To Drop Down List?

Apr 16, 2010

I am trying to populate table column names into a dropdown list . how can I query using Linq to SQL to just get the list of few Column names ? in a method in DAL which I can use to load in my UI page !!

View 2 Replies

Forms Data Controls :: Populating Multiple List Boxes Concurrently?

Jul 1, 2010

I have an ajax tab control and on each tab (4) there is a list box. Above the tab control is a button. What the user can do is select a tab, press the button to run the process. Each of the 4 processes does it's magic in the back ground and then dumps messages as it progresses to the list boxes. They work fine if I only run 1 and stay on that tab.

What I want to be able to do is to start a process on a tab, switch to another tab and start the process and be able to go back and forth to each tab to see the progress. Each tab has it's own timer control as well (set to 10 seconds).

View 3 Replies

Create Object For List In Or Out Of While Loop?

May 28, 2010

Create object for list in or out of while loop?

Code:

[code]....

My question is, is there any benefit to instantiating a new userDetails object in every loop, or can this be created outside the loop and title, forename and surname just written over with every pass of the loop?

View 3 Replies







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