Skip to content

How to bind the values to gridview?

Shanmugam Gk

Asked Dec 15, 2010, 2:12 AM EST3 answers
Share
LinkedInX
This is my code.......
 
NodeEnumerator myEnumerator = new NodeEnumerator(this.UltraWebTree1);
        string s = string.Empty;
        string s1 = string.Empty;
        while (myEnumerator.MoveNext())
        {
             s += myEnumerator.Current.Text + ": Level: "
                 + myEnumerator.Current.Level.ToString() + "
" +  myEnumerator.Current.TargetUrl +  "
" ;
                Response.Write(s);

            }
 
 
 
I am getting values from ultrawebtree and shows the values in aspx page....but i want to show the values in gridview...please give me the source code.....

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    0
    Generate DataTables, DataColumns, DataRows on runtime and bind it to GridView
    0
  • 0
    Thanks...i am generating DataTables, DataColumns, DataRows on runtime and bind it to GridView ....
    this is my code for that....
     
    NodeEnumerator myEnumerator = new NodeEnumerator(this.UltraWebTree1);
            string s = string.Empty;
            string s1 = string.Empty;
            while (myEnumerator.MoveNext())
            {
             
                    //s += myEnumerator.Current.Text + ": Level: "
                    //  + myEnumerator.Current.Level.ToString() + "
    " +  myEnumerator.Current.TargetUrl +  "
    " ;
                    s = myEnumerator.Current.Text;
                    s1 = myEnumerator.Current.TargetFrame;

                }
                //Response.Write(s);
                DataTable dt = new DataTable();
                dt.Columns.Add("Name");
                dt.Columns.Add("TargetUrl");
                DataRow dr = dt.NewRow();
                dr["Name"] = s;
                dr["TargetUrl"] = s1;
                dt.Rows.Add(dr);
                DataSet ds = new DataSet();  
                ds.Tables.Add(dt);
                GridView1.DataSource = ds;
                GridView1.DataBind();
           
        }
     
     
     
    but it shows the last value of ultrawebtree....it is not bind all the values...how can i do this...give me the solution...
    0
  • Suthish Nair
    0
    C#
    string s = string.Empty;
    string s1 = string.Empty; 
    DataTable dt = new DataTable();
    dt.Columns.Add("Name");
    dt.Columns.Add("TargetUrl");
    Code
    while (myEnumerator.MoveNext())
    {
     DataRow dr = dt.NewRow();
     dr["Name"] = myEnumerator.Current.Text.ToString();
     dr["TargetUrl"] = myEnumerator.Current.TargetFrame.ToString();
     dt.Rows.Add(dr);
    }
    Code
    DataSet ds = new DataSet();   
    ds.Tables.Add(dt);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    0