Delaring A String Thats Within A Loop Within Another Loop
Jan 14, 2010
Im stuck with declaring a string which is in a loop within another loop.
Dim CompanyDetails As String = ""
Dim CompanyRow As DataRow
For Each CompanyRow In newdt.Rows
CompanyDetails += CompanyRow(1) & " " & CompanyRow(0) & "<br/>"...
How can I get this to see the GetInfo as declared..... since its in a loop within a loop?
The repeater below allows a visitor to click a [+] to add a textbox. They can add as many as they need. Each textbox will contain a name.
[Code]....
I want to be able to collect all of the additional textboxes and add it to an string:
[Code]....
If for example the visitor added two textboxes and typed in "Mary" in the first and "Sue" in the second, I'd like "myAdditionalRegistrants" in the above string to be replaced with:
i have a checkboxlist that is being bind from a sqldatasource i want to be able to loop through whatever the user selects and store/update it to the data base. I want to do this with a foreach statement in my code behind but i dont know how since i dont have a listitems in the checkboxlist.
For Each Control In Page.Header.Controls How can I do something as above, at the moment getting the error "Control is a Type and Cannot be used as an expression" The Complete Code is as follows Try ' I only do this on my production servers, so I declare those here.'
If Request.ServerVariables("server_name") = [URL] Then ' Allow scripts and css to logged in CMS users' Dim checkLogin As New Controls.Login If checkLogin.IsLoggedIn <> True Then For Each Control In Page.Header.Controls If Control.GetType.Name = "EktronJsControl" Or Control.GetType.Name = "EktronCssControl" Or Control.GetType.Name = "EktronModalCss" Then Page.Header.Controls.Remove(Control) Else ' Removes the extra bubble inline style stuff that wasn't put in a CSS.'' Dim litControl As LiteralControl = Control If litControl.Text = Nothing Then litControl.Text = "" End If ' Removing blank.css file' Dim htmlLink As HtmlLink = Control If htmlLink.Href = "/css/blank.css" Then Page.Header.Controls.Remove(Control) End If End If Next End If End If Catch ex As Exception End Try`
I have an issue with a Loop that doesn't actually loop. I've posted a simplified version of my code below. Basically, using the NPOI excel library, I have an excel file with data on the first and second sheet, so I need to do a loop to get through both sheets. Below is what I have done so far, however this only works through the first sheet and then exits. It fails to increment the variable w. As you can see, there are other loops implemented in this code which function fine so I don't get it.It's been a very long day and perhaps I'm missing something very simple. I could have it placed wrong or something. If anyone else can spot what I might be doing wrong I'd be very grateful :)
public class SalesFileProcessor : ISalesProcessor { public List<FTPSalesRow> ProcessSalesFile(string filename)
new to C# question: I am in an iteration of a for loop and if a condition exists I want to jump to the next iteration of the for loop, how do I do this in C#?
I have some files listed on a listbox and want to upload them to the server. The values doesn't need to be selected. But I can't even get it working. Below is my source code:
I doing a nested for loop to achieve from #123,33.5,1283485089#44.6,Timestamp#124,66.7,timestamp#55.7,timestamp#125,76.4,timestamp#42.8,timest amp whole string to #123,33.5,1283485089#123,44.6,Timestamp#124,66.7,timestamp#124,55.7,timestamp#125,76.4,timestamp#125 ,42.8,timestamp. My code get me back same thing again
Dim i = 0 Dim rsplitdata As String() Dim row, item As String Dim inex Dim rdata As String() = TextBox1.Text.Split("#") For Each row In rdata rsplitdata = row.Split(",") If (i = 0) Then inex = rsplitdata(0) 'rdata(i) = inex + "," + rdata(i) Else rdata(i) = inex + "," + rdata(i) End If i = i + 1 Next For Each row In rdata rsplitdata = row.Split(",") For Each item In rsplitdata TextBox2.Text = TextBox2.Text + item.ToString + vbCrLf Next Next
I cant get my nested loop to output the right code:
If pagesreader.Read() Then ' if subtitle exists then output mydata = "<h2>" & pagesreader.Item("documentcategoryname") & "</h2>" While pagesreader.Read() mydata &= "<h2>" & pagesreader.Item("documentcategoryname") & "</h2>" If (pagesreader.Item("documentcat") = pagesreader.Item("documentcategoryid")) Then mydata &= "<p>" & pagesreader.Item("documentname") & "</p>" End If End While End If produces: About Us About Us doccy4 Map Of Medicine doccy5
When I need it to procude: About Us doccy3 doccy4 Map Of Medicine doccy
I'm stuck in converting the rate in the datalist. My page contain one dropdownlist(currency converter), one datalist - inside contain the price of bags in labels. Now I uses the dropdownlist.selectedIndexchange
[code]....
Althought it did convert the rate, but it only convert the first row.
I need to loop through all the controls in my asp.net webpage and do something to the control. In one instance I'm making a giant string out of the page and emailing it to myself, and in another case I'm saving everything to a cookie. The problem is masterpages and items with collections of controls inside them. I want to be able to pass in a Page to the method, then have that method be generic enough to loop through all controls in the inner-most content page and work with them. I've tried doing this with recursion, but my recursion is incomplete. I want to pass a Page object into a method, and have that method loop through all controls in the innermost content page. How can I achieve this?
private static String controlToString(Control control) { StringBuilder result = new StringBuilder(); String controlID = String.Empty; Type type = null; foreach (Control c in control.Controls) { try { controlID = c.ID.ToString(); if (c is IEditableTextControl) { result.Append(controlID + ": " + ((IEditableTextControl)c).Text); result.Append("<br />"); } else if (c is ICheckBoxControl) { result.Append(controlID + ": " + ((ICheckBoxControl)c).Checked); result.Append("<br />"); } else if (c is ListControl) { result.Append(controlID + ": " + ((ListControl)c).SelectedValue); result.Append("<br />"); } else if (c.HasControls()) { result.Append(controlToString(c)); } //result.Append("<br />"); } catch (Exception e) { } } return result.ToString(); } Without Try/catch Object reference not set to an instance of an object. On line controlID = .....
Ok heres the scenario: I have a table with many rows in it. Each row has a checkbox in one cell, and a span in another cell. What I want to do in my jquery is to go through the table and find each row where the checkbox is checked, and then store the value of the span in an array. I thought you might be able to do it as a selector rather than using a loop. I tried this but it didn't work
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 have a datatable with 1 record only, can I reference the data in the row without a for loop? I can get to the data by using the following code, but it would be nice if I didn't have to use the For loop.
foreach (DataRow row in dataTable.Rows) { string name = row["Name"].ToString(); string id = row["ID"].ToString(); }
I have only one row therefore may i get its records without for loop or foreach loop