.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

iterate through for each

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
hey im attaching a link to my database image  http://img521.imageshack.us/img521/3299/60742123.png hello, i was wondering what am i doing wrong im using the code below to iterate through each row in my database and print out a certin code for each existing row in my db but for some reason it only prints out the last row.. any ideas? DataTable Info = Cameras.GetCamerasPageInfo(); foreach (DataRow Images in Info.Rows) { string ImgName = Images.ItemArray[4].ToString().Trim(); string Title = Images.ItemArray[5].ToString().Trim(); string Desc = Images.ItemArray[6].ToString().Trim(); Literal2.Text = @"<li><a href=" + "\"Img/" + ImgName + "" + "\">"; Literal2.Text = Literal2.Text + @"<img src=" + "\"Img/" + ImgName + "" + "\" height=" + "\"60px" + "\" "; Literal2.Text = Literal2.Text + @"title=" + "\"" + Title + "\" alt=" + "\"" + Desc + "\"" + "></a></li>"; }  

View Complete Post

More Related Resource Links

how can i iterate through a table using javascript



how can i iterate through a table using javascript

each row in a table shows a  a  decimal value , i want to calculate the total  with out using server codes


Iterate through profile information


I have a site I'm working on where the values being stored in user profiles can change so I need to iterate through all available profile options and display them (say in a label or gridview for instance).

Here is an example of a web.config I threw together

<profile enabled="true">
        <group name="Demographics">
        <add name="FirstName" type="String"/>
        <add name="LastName" type="String"/>

Failure to reliably iterate through all elements of a COM Collection from C# .NET 4.0

In C#, .NET 4.0, I am making a call to a COM DLL to return a collection object. A foreach loop steps through each element of the collection. In the loop, a new .NET object is created for each element of the COM collection. The new object is added to a new .NET collection. This works fine in the development environment. In a deployed system, is works correctly most (about 90%) of the time.  However, sometimes (about 5% of the time) the foreach loop finds no items in the COM collection. Other times (also about 5%), it finds the first 2 or 3 or ... N items.  Somehow, the enumeration interface exposed by the COM object is failing. Here is a code snippet from the COM Object, which is called NameList.  NOTE that the VB6 cls file was opened in a text editor to show the class and method attributes. VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "NameList" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = True Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes" Attribute VB_Ext_KEY = "Top_Level" ,"Yes" Option Explicit Private mCol As Collection ' <snip> Only code rela

Iterate through rows of dataset in report's custom code

Hello, How can I iterate through the rows of a dataset in the custom code? I have a report containing a dataset. I pass the dataset as a parameter to the custom code function. But what then? Where is a reference about the available members etc.? Here is my dummy sample code so far: Public Function ShowParameterValues(ByVal ds as DataSet) as object() Dim codes() As Object Array.Resize(codes,dc.???.Count) codes(0)=ds??(field???)(row??) return codes End Function As the task I want to accomplish is very simple, I want to keep it in the custom code instead of writing any custom assemblies etc.   Thank you!

Iterate through all areas

I am wondering if MVC offers a handy function to iterate through all areas.  I know I can search the sub-directories of Areas to achieve this.  I am just curious.

iterate till to get n-th level of foreign key inforamtion.

Hi.. how can i fetch n-th level of all foreign key's information? for example: one table is 'A', second table name is 'B', third tables is 'C' and so on table 'A' has a primary key, table 'B' has foreign key against table 'A' and table 'C' has foreign key of table 'B' and so on.. i want to make a such dynamic script which can get all/n-th level of foreign key relation inofrmations against. i made below script which can get foreign key information dynamically but it is used for single level not for n-th level. ALTER PROC [dbo].[sp_sng_fetching_foreign_key_info] @p_table_name varchar(100) , @flag bit AS DECLARE @pk_table_nme VARCHAR(150) DECLARE @fk_table_nme VARCHAR(150) DECLARE @pk_col_nme VARCHAR(150) DECLARE @fk_col_nme VARCHAR(150) DECLARE @constraint_nme VARCHAR(150) DECLARE @flg bit BEGIN set @flg = @flag DECLARE GETTING_ALL_FOREIGN_KEY_DATA CURSOR FOR select ISNULL(c.constraint_name,''), ISNULL(cfk.table_name ,''), ISNULL(kcu.column_name ,''), ISNULL(cpk.table_name ,''), ISNULL(pkt.column_name ,'') from information_schema.REFERENTIAL_CONSTRAINTS c INNER JOIN information_schema.TABLE_CONSTRAINTS cpk on c.unique_constraint_name = cpk.constraint_name INNER JOIN information_schema.TABLE_CONSTRAINTS cfk on c.constraint_name = cfk.constraint_name INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu ON c.constrai

How do i iterate through an XML document?

hi friends, i have tried to read through an xml variable and insert values to a table using the following fucntion:   if exists (select 1 from sys.sysobjects where type = 'TF' and name = 'fn_get_int_table_frm_xml') drop function fn_get_int_table_frm_xml go create function fn_get_int_table_frm_xml ( @xml_values xml ) returns @indexes table (idx int identity(1, 1) primary key, usr_id int, Role_id int) as begin declare @ret xml declare @rle_id, @usr_id int set @ret = @xml_values select UserID, RoleID from openxml('@ret', 'Roles/Role'); -- how to insert each child element to the @indexes table? return end go The @xml_values content is like this: <Roles> <Role> <UserID>10</UserID> <RoleID>200</RoleID> </Role> <Role> <UserID>10</UserID> <RoleID>300</RoleID> </Role> <Role> <UserID>10</UserID> <RoleID>400</RoleID> </Role> </Roles>' How do i extract each UserID and ROleID in each Role and insert to the virtual table @Indexes? thanks

Iterate data row to find errors.


Hi, I have an asp website, and a dataset with a datatable. When I check I after configuring it it shows all the data. But when I run the code I got an exception

System.Data.ConstraintException was unhandled by user code
  Message="Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."

I want to figure it out with iterating datarow.

Some codes are here but I need help to iterate datarow.

public partial class tabRegionExtremeList : System.Web.UI.Page
    DataSet1TableAdapters.droughtDataTableAdapter k1 = new DataSet1TableAdapters.droughtDataTableAdapter();
    DataSet1.droughtDataTableDataTable k2 = new DataSet1.droughtDataTableDataTable(); 
    String [][]ExtremeList;
    protected void Page_Load(object sender, EventArgs e)
    private void getRegionExtremeList()
            // How to catch error by iterating Datarow here
            // such as using 
          // foreach(...)



iterate throw rows of Template Column in Datagrid



I am using WPF DataGrid (VS 2008). i am using Template column with a button in it i want to change the content of the button(Caption) when it is clicked .i am doing it in its click event ,but it  changes the content of only the button clicked(only one row). i want to change the content of button in all rows.

how can access the button instance of all rows in this template column.



How do i iterate through a table that does not have an index column?


hi friends,

I have the following table variable that i store rows extracted from an xml document;

declare @tbl_ans table ( AnsText nvarchar(max), IsCorr bit)

this cannothave an index column.

assume it has 25 rows, i need insert each row to a table  that has three columns

That Answers table has following structure:

a_idx int,

a_text nvarchar(max),

is_active int,

upt_date datetime

The script should iterate through the @tbl_ans_table table and insert each to the answers table then i should fetch each a_idx in each iteration and insert it to another. But the problem is how itereate through @tbl_ans_table without an index?



Iterate the rows in the datagrid and compare it with the systemclock



How would I iterate the rows in the datagrid? The 4th column contains the time, I would like to compare it with the systemclock and enter "ACTIVE" in the 5th column if the time value in the 4th column is equal to the system clock?

I tried FOR EACH.. but I can't get it right.. Please help.

How do I programmatically iterate through different pages in a GridView?


OK I am a total novice to VB so bear with me.In my web-based project, I pass an ID field as a parameter in my URL and go through each row in my gridview to find the correct row that matches the ID parameter, like so: 

Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.DataBound
 REM if valid ID parameter was given in URL
 If Not Request.QueryString("ID") Is Nothing AndAlso _
  IsNumeric(Request.QueryString("ID")) Then
  Dim bItemNotFound As Boolean = True
  Dim i As Integer
  Dim iSelectedIndex As Integer = -1

  REM Loop through the items in the GridView
  For i = 0 To GridView1.DataKeys.Count - 1 Step i + 1

   REM Found the correct item
   If Request.QueryString("ID") = GridView1.DataKeys(i).Value Then
    bItemNotFound = False
    iSelectedIndex = i
    Exit For
   End If

  If bItemNotFound = False Then
   GridView1.SelectedIndex = iSelectedIndex
   GridView1.SelectedIndex = -1
  End If

 End If
End Sub

The problem is that this code only works if the corresponding ID is in a row displayed on the first page. I want to loop through each page in the gridview's rows until either the correct ID is found or it reaches the end of the data set. How do I

How to iterate to Profile pictures?


User stored his/her profile picture in "Shared%20Pictures/Profile%20Pictures/bhind8ball.bmp" path in SSP. How to get this List item using this url? Or How to iterate SharePicture/ProfilePicture to get this List item using SPQuery?


Please share thoughts.


How can I iterate through all ActivityDesigners contained within a WorkflowDesigner?


I want to iterate through all the activity designers present in a WorkflowDesigner ... the WorkflowDesigner has been loaded with a root Flowchart activity, and the flowchart will contain all kinds of different activities.  I've tried to do this by using the ModelService object, but for some reason it's hanging on the Find() method.  Is there another/better way to do that?

This is what I'm trying currently:

      ModelService modelSvc = this.wd.Context.Services.GetService<ModelService>();
      IEnumerable<ModelItem> activityCollection = modelSvc.Find(modelSvc.Root, typeof(Activity));
      List<ModelItem> activityList = activityCollection.ToList<ModelItem>();

      foreach (ModelItem item in activityList)
        StartWorkflowActivityDesigner designer = item.View as StartWorkflowActivityDesigner;
        if (designer != null)
          designer.ExpandState = true;



How to add double integer array to ArrayList. Then iterate through the list and delete an item?


   I have a class with three students in it. Each student has two test scoress for the semester.
   How do I iterate through my ArrayList?

   Also suppose I want to remove a student score from the ArrayList while iterating through the list, How can I do this ?

   An example is if I allow Hallie to drop her lowest score of 71

            int Students=3;
            int Scores = 2;
            int[,] Student = new int[Students, Scores];

            ArrayList Class = new ArrayList();
            // Add joes scores
            Student[0, 0] = 88;
            Class.Add(Student[0, 0]);
            Student[0, 1] = 99;
            Class.Add(Student[0, 1]);

            // Add Maries Scores

Iterate through XML in SP


I am passing XML to the SP from .NET. My xml format is as follow.

<docs key1="value1" key2="value2">
   <Item id="1">Item Name</Item>
   <Item id="2
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend