Question : How to get text from a site with jQuery

Hi,

I have the following generated HTML code and at the end there's a dynamic number inside () that I need to pick up with either jQuery or JavaScript. How do I best do this (I cannot get elements by name or ID, only by title or what they contain)?

1:
2:
3:
4:
5:
6:
7:
8:
9:
<TBODY id="titl8-1_" groupString="objective"><TR>
<TD colspan="100" class="ms-gb"  nowrap>
<img src="/_layouts/images/blank.gif" alt="" height=1 width=0><a href="javascript:" 
onclick="javascript:ExpCollGroup('8-1_','img_8-1_');return false;">
<img id="img_8-1_" src="/_layouts/images/minus.gif" 
alt="Expand/Collapse" border="0"></a>
&nbsp;<a href="javascript:" onclick="javascript:ExpCollGroup('8-1_','img_8-1_');
return false;">Item Level</a> :&nbsp;Strategic Objective 
<span style="font-weight: lighter">&#8206;[b](8)[/b]</span></TD></TR></TBODY>


Thanks in advance.

Answer : How to get text from a site with jQuery

Hi,

Please check link for solution:
http://niitdeveloper.blogspot.com/2010/07/display-image-instead-of-checkbox-in.html.

Here you can download the project for the same.

Here is the code snippet of the file Form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;

namespace ee_DataGrid
{
   public partial class Form1 : Form
   {
       // gridViewData is the name of the DataGridView
       private Bitmap trueImg, falseImg;
       public Form1()
       {
           InitializeComponent();

           trueImg = (Bitmap)Image.FromFile(Application.StartupPath + @"\Images\true.png");
           falseImg = (Bitmap)Image.FromFile(Application.StartupPath + @"\Images\false.png");
           
           // Sorting image with this event
           gridViewData.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(gridViewData_ColumnHeaderMouseClick);
       }      

       private void btnGetData_Click(object sender, EventArgs e)
       {
           try
           {
               #region Filling DataGridView named gridViewData values
               String connectionString = "Initial Catalog=TestDB;Data Source=localhost; Uid=sa; pwd=god";
               SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM UID", connectionString);
               SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

               DataTable table = new DataTable();
               dataAdapter.Fill(table);
               gridViewData.DataSource = table;
               gridViewData.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);                

               #endregion

               #region Showing image instead of checkbox

               // Hiding checkbox values
               gridViewData.Columns["Is Indian"].Visible = false;

               DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
               imageCol.Name = "Is Indian";
               imageCol.SortMode = DataGridViewColumnSortMode.Automatic;
               gridViewData.Columns.Add(imageCol);
               
               foreach (DataGridViewRow row in gridViewData.Rows)
               {
                   if (row.Cells["Is Indian"].Value != null)
                   {
                       if (Convert.ToBoolean(row.Cells["Is Indian"].Value))
                       {
                           // Cells[3] is the position of the cell in the row
                           row.Cells[3].Value = trueImg;
                       }
                       else
                       {
                           row.Cells[3].Value = falseImg;                            
                        }
                   }
               }
               #endregion
           }
           catch (Exception exc)
           {
               MessageBox.Show("Contact Developer\nTechnical Report: " + exc.ToString());
           }
       }

       void gridViewData_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
       {
           foreach (DataGridViewRow row in gridViewData.Rows)
           {
               if (row.Cells["Is Indian"].Value != null)
               {
                   if (Convert.ToBoolean(row.Cells["Is Indian"].Value))
                   {
                       // Cells[3] is the position of the cell in the row
                       row.Cells[3].Value = trueImg;
                   }
                   else
                   {
                       row.Cells[3].Value = falseImg;
                   }
               }
           }
       }
   }
}

Do write back for more explanation and help.


Random Solutions  
 
programming4us programming4us