Web Forms :: How To Get Array Elements By ForEach Loop With Counter
Apr 27, 2016
I want to get Array Elements by ForEach loop with Counter ..
whislist = dsddsds.Tables[0].Rows[0]["wishtlist_clg"].ToString().Split(',');
int i = 0;
foreach (string id in whislist) {
if (i != 0) {
tarsk.Value="1";
} else {
tarsk.Value="0";
}
whislist =525,1315,1331;
TARSK is an hidden field....
I want if whitelist is not in blank then 1 not equal to 0 is True other false but yet false condition is fire....
i'd like to be able to check to see if an item with the same id has already been placed in the database, if so to then update the quantity for that item, however due to the fact I have this in a foreach loop it will update the quantity for each item.
When I placed the Command outside of the loop I am unable to use 'ItemID' as it's not in context, is there anyway I can get around this?
foreach (UserItem ItemID in (List<UserItem>)Session["UserSession"]) { ConclusionPage.InsertCommand = "IF EXISTS (SELECT ItemID FROM tblUserItems WHERE UserID='@CurrentUser' AND ItemID='@ItemID') UPDATE tblUserItems SET Quantity = Quantity+1 WHERE (UserID = '@CurrentUser') AND (ItemID = '@ItemID')"; ConclusionPage.Insert(); }
I'm using a foreach to loop through an IList of objects in a Partial View in ASP.NET MVC.
Here's the entire code (Message is one of my classes from the Model).
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList<Message>>" %> <% if (ViewData.Model.Count > 0) { foreach (MvcTest.Models.Message m in ViewData.Model) { Response.Write(m.RenderHtml()); } }
ie explicitly declaring a variable for the IList rather than just using the (strongly-typed) Model, and it works fine.
in my asp.net mark up I have a foreach loop that iterates through a simple list. In this foreach loop I am adding a new user control and attempting to pass in the value from the loop. However, this value just wont budge and get inside that damn control!
<%foreach (userInfo i in this.items) { %> <uc1:ItemControl ID="ItemControl" runat="server" UserID='<%#Eval("userID") %>'/> <%} %>
userID is a public property in the control, when it goes to set, the value is just literally :
<%#Eval("userID") %>. I've tried #Bind and =Value but nothing seems to work.
I am trying to do some basic. Display customer testimonials in a table using foreach loop and have a checkbox on each row. Once checked, update the table.
I have a stored procedure of complex type in my entity framework. Here is my View.
List<string> IDs = new List<string>(); XDocument doc = XDocument.Parse(xmlFile); var query = from c in doc.Root.Elements("a").Elements("b") select new { ID = c.Element("val").Value};
How can I convert query to List without loop foreach ?
basically, the InstellingGegevens table gest filled in by some procedure from another server. the thing i then need to do is check if there are new records in this table, and fill in the new ones in Instellingens.
this code runs for like 4 minutes on 15k records. how do I optimize it? or is the only way a Stored Procedure?
this code runs in a timer, running every 6h. IF a stored procedure is best, how to I use that in a timer?
I am saving for each user a session with information about his current page viewing.
Each time the user is moving to a new page, I am updating the session with the new page he is right now.
Now, my question is if I can make any loop over all of my users session and answer a question like: How many users are now on page "2.aspx" for example?
We have a project that needs to gather survey data. On one particular page of the website, there are 21 questions each with a scale of 1-5 where the user selects one radio button for each question in the table.
The survey is being coded in VB.NET. The data submits to an SQL database. All the radio buttons are similarly named, so only the number changes for the question -- thinking this would make it easier on the back end coding. In the code behind I was hoping to do something to the effect:
We have a project that needs to gather survey data. On one particular page of the website, there are 21 questions each with a scale of 1-5 where the user selects one radio button for each question in the table.
The survey is being coded in VB.NET. The data submits to an SQL database. All the radio buttons are similarly named, so only the number changes for the question -- thinking this would make it easier on the back end coding. In the code behind I was hoping to do something to the effect:
For i = 1 To 21 If rbLWHFQ_Q(i)A1.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A1.Value) ElseIf rbLWHFQ_Q(i)_A2.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A2.Value) ElseIf rbLWHFQ_Q(i)_A3.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A3.Value) ElseIf rbLWHFQ_Q(i)_A4.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A4.Value) ElseIf rbLWHFQ_Q(i)_A5.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A5.Value) ElseIf rbLWHFQ_Q(i)_A6.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A6.Value) ElseIf rbLWHFQ_Q(i)_A7.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A7.Value) ElseIf rbLWHFQ_Q(i)_A8.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A8.Value) ElseIf rbLWHFQ_Q(i)_A9.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A9.Value) ElseIf rbLWHFQ_Q(i)_A10.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A10.Value) End If Next i
My research tells me that it's not possible to do what I am wanting without some special coding. I've seen mention of arrays in relation to these types of questions elsewhere, but I'm not familiar enough with arrays to see how they would work in this case.
Am I just going to have to create 21 sets of If...Else statements? :(
Here's what the HTML looks like for a question, if that matters:
As an aside, I know about RadioButtonLists, but in this case I'm needing to style the radio buttons in a special way and can't get it to work when ASP renders the list items.
Updated to show I used it in my code I'm not sure how StackOverflow works with regards to showing how something worked for you, but I just wanted to add this in case others come here looking for the answer. Basically, I used the code below:
Dim radioButtons()() As HtmlInputRadioButton = { _ New HtmlInputRadioButton() {rbLWHFQ_Q1_A1, rbLWHFQ_Q1_A2, rbLWHFQ_Q1_A3, rbLWHFQ_Q1_A4, rbLWHFQ_Q1_A5, rbLWHFQ_Q1_A6}, _ New HtmlInputRadioButton() {rbLWHFQ_Q2_A1, rbLWHFQ_Q2_A2, rbLWHFQ_Q2_A3, rbLWHFQ_Q2_A4, rbLWHFQ_Q2_A5, rbLWHFQ_Q2_A6}, _ }
I created an array with the radio button group names:
Dim radioButtonGroupNames() As String = { _ "@LWHFQ_Q1", _ "@LWHFQ_Q2", _ }
Then in my For...Loop I used:
For i = 0 To 20 If radioButtons(i)(0).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(0).Value) ElseIf radioButtons(i)(1).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(1).Value) ElseIf radioButtons(i)(2).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(2).Value) ElseIf radioButtons(i)(3).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(3).Value) ElseIf radioButtons(i)(4).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(4).Value) ElseIf radioButtons(i)(5).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(5).Value) End If Next i
as a php developer ive been told to go the MVC route which ive been trying since yesterday. Im using visual web delveloper 2010 express and im using the MVC template project.Ive basically got a news table in MSSQL Express, in there are these fields ID,(Title,Body,PostedOn,PostedBy) all i wanna do is loop through them to put them on the view.Im after a nudge in the right direction, I want to be able to do a SQL lookup in the controller put that data in a DataTable then run a foreach loop on the table to display this on the view. The problem im getting is I know youre not suppsed to put any HTML in the controller and I cant pass the datatable to the view to do the loop in the view.. so where/how do I do the loop.
everthing is working fine. But when the exception rises the exception shown in command prompt.
What i need is .. when the exception rises .. i need to stop my execution for 2 minutes and then start the loop from the same element .. like using goto statment... but for loop it is working fine .. how to implemnt that logic for mydatareader.read().
i just would like to ask..i have generate the number of date using loop.. when i insert the start date eg 1/1/2010 and the end date as 12/12/2010.. and the gap between the date should be one week..eg of the result should look like this in the web form:
1/1/2010 8/1/2010 15/1/2010.......till 12/12/2010
thus, i would like to ask, how can i pass all the generated date to sql database..do i need to store those date in an array before pass them to database.. if so, how can i pass those date to an array??
I'm not sure if this is the right forum to ask. But I'm using ASP.net 3.5 & I've below code:
[Code]....
Now, I want to check how many elements are present in this distinct array & if the number of elements in this distinct array is more than 500, then I need to fetch only those first 500 elements. How can I achieve this?
I have LINQ result, and I have List.I want to do Where() on the LINQ and to REMOVE all the matching strings from the List.I get errors of:Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operato
I need to build an array of implicit objects in a var object by looping through a List and adding the to the array. For example...
Code: var data = new[] { new { Name = "China", Value = 1336718015 }, new { Name = "India", Value = 1189172906 }, new { Name = "United States", Value = 313232044 }, new { Name = "Indonesia", Value = 245613043 }, new { Name = "Brazil", Value = 203429773 },};
If I wanted to dynamically add new objects with the Name and Value values above by a looping through an existing List, how would I go about it?
I want to data bind jQuery Counter just like we do to Ajax Counter. Also I would like to know that do we have events for jQuery counter just like we have a tick event in Ajax Counter?
I've got a while loop that's doing some stuff, and what I want is for it to create a new array each time.
while(condition){ //do some stuff //create an array x[] //amend values in array //save as new array each time until loop finished }
Actually i need to store the comma separated values of different datatypes in an array using split.And then i hav to sort these values comparing zeroth position element of all rows.
I have a problem that when i bring the array of asp and use it in the javascript, When i use the counter (i++) and print for each index of array just like "<%=app[i] %>" and it is not return the value back to me.i solve this problem for a dayedit