0

I want to get the even columns only by using while loop without ienumerators. While loop must be in index format.

The code is following:

protected void Page_Load(object sender, EventArgs e)
        {

            string query = "SELECT * FROM Notifications_ WHERE News_Status='1'";

            connection  obj_con= new connection();


            SqlCommand myCommand = new SqlCommand(query);

            DataSet ds = obj_con.executeQueryDataSet(myCommand);

            String temp_data = "<table> <tr><h2 align='center' style='background-color:#00254c; color:white; vertical-align:top'>Highlights</h2></tr><tr><td> </td></tr><tr><td> </td><td> </td></tr><tr><td></td><td> </td></tr>";



            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    temp_data = temp_data + "<tr></tr><tr><td style='background-color:gray; color:white'><b>" + row["News_Day"] + "</b></td></tr><tr><td style='background-color:#f6f6f6; color:#00254c'><h2 align='center'>" + row["News_date"] + "</h2></td><td style='color:#00254c'><b>" + row["News_title"] + "</b></td></tr><tr><td></td><td><a href=" + row["News_Link"] + " style='color:GrayText; text-decoration:none'>" + row["News_Desc"] + "</td></tr>";
                }
            }

            this.notification_data.InnerHtml = temp_data + "</table>";
        }
Saravana Kumar
  • 3,669
  • 5
  • 15
  • 35

1 Answers1

0

You can try like this as shown in this example code.

string[] columnNames = (from dc in table.Columns.Cast<DataColumn>()
                        select dc.ColumnName).ToArray();


do
    {
       if (i%2==0)
           //do something here
        i++;
    } while (i < columnNames.Length);
BSG
  • 2,084
  • 14
  • 19