Databind Array to DataGrid

Hi

Can anyone help with this problem, I want to databind the following variables to a datagrid called id="QueryResults"

Variables: HighlightBody, HighlightTitle, HighlightURL




The code for the array is below, anyone know how to do this.

void Page_Load(Object Src, EventArgs E)
{
inputString = Request.QueryString["TxtQuery"];
                         string[] words = GetQueryStringToArray(Request.QueryString["TxtQuery"].ToString()) ;
                    Word1 = words[0];
                    Word2 = words[1];
                    Word3 = words[2];
                    Word4 = words[3];
                    Word5 = words[4];
                    Word6 = words[5];
                    HighlightBody = spQueryResults.FieldValue("PageDescription", null);
                    HighlightBody = Regex.Replace(HighlightWord, Word1, "\b<strong>"+Word1+"</strong>", RegexOptions.IgnoreCase);
                    HighlightBody = Regex.Replace(HighlightWord, Word2, "\b<strong>"+Word2+"</strong>", RegexOptions.IgnoreCase);
                HighlightBody = Regex.Replace(HighlightWord, Word3, "\b<strong>"+Word3+"</strong>", RegexOptions.IgnoreCase);
                    HighlightBody = Regex.Replace(HighlightWord, Word4, "\b<strong>"+Word4+"</strong>", RegexOptions.IgnoreCase);
                HighlightBody = Regex.Replace(HighlightWord, Word5, "\b<strong>"+Word5+"</strong>", RegexOptions.IgnoreCase);
                    HighlightBody = Regex.Replace(HighlightWord, Word6, "\b<strong>"+Word6+"</strong>", RegexOptions.IgnoreCase);

                HighlightTitle = Regex.Replace(HighlightWord, Word1, "\b<strong>"+Word1+"</strong>", RegexOptions.IgnoreCase);
                    HighlightTitle = Regex.Replace(HighlightWord, Word2, "\b<strong>"+Word2+"</strong>", RegexOptions.IgnoreCase);
                HighlightTitle = Regex.Replace(HighlightWord, Word3, "\b<strong>"+Word3+"</strong>", RegexOptions.IgnoreCase);
                    HighlightTitle = Regex.Replace(HighlightWord, Word4, "\b<strong>"+Word4+"</strong>", RegexOptions.IgnoreCase);
                HighlightTitle = Regex.Replace(HighlightWord, Word5, "\b<strong>"+Word5+"</strong>", RegexOptions.IgnoreCase);
                    HighlightTitle = Regex.Replace(HighlightWord, Word6, "\b<strong>"+Word6+"</strong>", RegexOptions.IgnoreCase);
               
               
                    HighlightURL = Regex.Replace(HighlightWord, Word1, "<strong>"+Word1+"</strong>", RegexOptions.IgnoreCase);
                    HighlightURL = Regex.Replace(HighlightWord, Word2, "<strong>"+Word2+"</strong>", RegexOptions.IgnoreCase);
                HighlightURL = Regex.Replace(HighlightWord, Word3, "<strong>"+Word3+"</strong>", RegexOptions.IgnoreCase);
                    HighlightURL = Regex.Replace(HighlightWord, Word4, "<strong>"+Word4+"</strong>", RegexOptions.IgnoreCase);
                HighlightURL = Regex.Replace(HighlightWord, Word5, "<strong>"+Word5+"</strong>", RegexOptions.IgnoreCase);
                    HighlightURL = Regex.Replace(HighlightWord, Word6, "<strong>"+Word6+"</strong>", RegexOptions.IgnoreCase);
                   
               
          }
     public string[] GetQueryStringToArray(string inputString)
          {
            string[] finalSetOfWords = new string[6];
               char[] separators = {' '};
               string[] words = inputString.Split(separators);
               
               for ( int i=0; i < 6; i++)
               {
                    if(words.Length > i && inputString.Trim().Length > 0)
                    {
                         finalSetOfWords[i] = words[i];
                    }
                    else
                    {
                         finalSetOfWords[i] = "NNN";
                    }
               }
               return finalSetOfWords;
                 
          }

Any help would be much appreciated
Caz


BeginningWebDesignAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NipNFriar_TuckCommented:
Hi Caz, you can bind say an ArrayList of objects to a datagrid by

ArrayList al = new ArrayList();
DataGrid dg = new DataGrid();
dg.DataSource  = al;
dg.DataBind();

This works great especially if dealing with classes say for instance...

public class MyClass {
     private string body = string.Empty;
     private string title = string.Empty;
     private string url = string.Empty;
     public string Body {
          get { return "<strong>" + body + "</strong>"; }
          set { body = value; }
     }
     public string Title {
          get { return "<strong>" + title + "</strong>"; }
          set { title = value; }
     }
     public string URL {
          get { return "<strong>" + url + "</strong>"; }
          set { url = value; }
     }
     public MyClass() {}
     public MyClass( string Body, string Title, string URL ) {
          this.Body = Body;
          this.Title = Title;
          this.URL = URL;
     }
}

Then add MyClass to the al and you are done...

You may want to check out this site for more info:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsdatagridclasstopic.asp

NOTE: The examples given here are done with a datatable, you can use a collection such as an ArrayList or classes instead of a datatable with the same result.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.