Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. error while generate gridview programmatically

error while generate gridview programmatically

Scheduled Pinned Locked Moved ASP.NET
helpcom
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    findtango
    wrote on last edited by
    #1

    hi i want generate gridview programmatically to but having a error in hyp1.DataNavigateUrlFields = "link"; ERROR:- cannot implicitly convert type 'string' to 'string[]' plzzzz help me thanks in advance DataTable dt = new DataTable("dtable"); DataRow dr1; DataRow dr2; dt.Columns.Add(new DataColumn("Text", typeof(string))); dt.Columns.Add(new DataColumn("link", typeof(string))); dr1 = dt.NewRow(); dr1[0] = "Yahoo"; dr1[1] = "http://www.yahoo.com"; dt.Rows.Add(dr1); dr2 = dt.NewRow(); dr2[0] = "Google"; dr2[1] = "http://www.google.com"; dt.Rows.Add(dr2); GridView GV = new GridView(); GV.AutoGenerateColumns = false; HyperLinkField hyp1 = new HyperLinkField(); hyp1.HeaderText = "UsefulLinks"; hyp1.DataTextField = "Text"; hyp1.DataNavigateUrlFields = "link"; hyp1.Target = "_blank"; GV.Columns.Add(hyp1); GV.DataSource = dt; GV.DataBind(); plhPlaceHolder.Controls.Add(GV);

    K 1 Reply Last reply
    0
    • F findtango

      hi i want generate gridview programmatically to but having a error in hyp1.DataNavigateUrlFields = "link"; ERROR:- cannot implicitly convert type 'string' to 'string[]' plzzzz help me thanks in advance DataTable dt = new DataTable("dtable"); DataRow dr1; DataRow dr2; dt.Columns.Add(new DataColumn("Text", typeof(string))); dt.Columns.Add(new DataColumn("link", typeof(string))); dr1 = dt.NewRow(); dr1[0] = "Yahoo"; dr1[1] = "http://www.yahoo.com"; dt.Rows.Add(dr1); dr2 = dt.NewRow(); dr2[0] = "Google"; dr2[1] = "http://www.google.com"; dt.Rows.Add(dr2); GridView GV = new GridView(); GV.AutoGenerateColumns = false; HyperLinkField hyp1 = new HyperLinkField(); hyp1.HeaderText = "UsefulLinks"; hyp1.DataTextField = "Text"; hyp1.DataNavigateUrlFields = "link"; hyp1.Target = "_blank"; GV.Columns.Add(hyp1); GV.DataSource = dt; GV.DataBind(); plhPlaceHolder.Controls.Add(GV);

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      It is expecting a string array. So you need some code like this: string[] tmp = new string[1] {"link"}; hyp1.DataNavigateUrlFields = tmp; Hope that helps. Ben

      F 1 Reply Last reply
      0
      • K kubben

        It is expecting a string array. So you need some code like this: string[] tmp = new string[1] {"link"}; hyp1.DataNavigateUrlFields = tmp; Hope that helps. Ben

        F Offline
        F Offline
        findtango
        wrote on last edited by
        #3

        i m using datatable field to bind link to that field how to convert that field in a string array

        K 1 Reply Last reply
        0
        • F findtango

          i m using datatable field to bind link to that field how to convert that field in a string array

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          Isn't the field just called "link"? I am not sure what your issue is? You tried the code I posted and it didn't work? What error did you get? Ben

          F 1 Reply Last reply
          0
          • K kubben

            Isn't the field just called "link"? I am not sure what your issue is? You tried the code I posted and it didn't work? What error did you get? Ben

            F Offline
            F Offline
            findtango
            wrote on last edited by
            #5

            i m try to generate gridview programmatically and want to bind data from database, BUT first i create a datatable n try to bind it with gridview. the method u suggest (string[] tmp = new string[1] {"link"}; ) in not properly working in this code at line no.8 and 12, i specify that link which is bind with field (hyp1.DataNavigateUrlFields = "link";) so that when i click on the link it open that site. when i try to run the application i got error msg :- cannot implicitly convert type 'string' to 'string[]' 1 DataTable dt = new DataTable("dtable"); 2 DataRow dr1; 3 DataRow dr2; 4 dt.Columns.Add(new DataColumn("Text", typeof(string))); 5 dt.Columns.Add(new DataColumn("link", typeof(string))); 6 dr1 = dt.NewRow(); 7 dr1[0] = "Yahoo"; 8 dr1[1] = "http://www.yahoo.com"; 9 dt.Rows.Add(dr1); 10 dr2 = dt.NewRow(); 11 dr2[0] = "Google"; 12 dr2[1] = "http://www.google.com"; 13 dt.Rows.Add(dr2); 14 GridView GV = new GridView(); 15 GV.AutoGenerateColumns = false; 16 HyperLinkField hyp1 = new HyperLinkField(); 17 hyp1.HeaderText = "UsefulLinks"; 18 hyp1.DataTextField = "Text"; 19 hyp1.DataNavigateUrlFields = "link"; 20 hyp1.Target = "_blank"; 21 GV.Columns.Add(hyp1); 22 GV.DataSource = dt; 23 GV.DataBind(); 24 plhPlaceHolder.Controls.Add(GV);

            K 1 Reply Last reply
            0
            • F findtango

              i m try to generate gridview programmatically and want to bind data from database, BUT first i create a datatable n try to bind it with gridview. the method u suggest (string[] tmp = new string[1] {"link"}; ) in not properly working in this code at line no.8 and 12, i specify that link which is bind with field (hyp1.DataNavigateUrlFields = "link";) so that when i click on the link it open that site. when i try to run the application i got error msg :- cannot implicitly convert type 'string' to 'string[]' 1 DataTable dt = new DataTable("dtable"); 2 DataRow dr1; 3 DataRow dr2; 4 dt.Columns.Add(new DataColumn("Text", typeof(string))); 5 dt.Columns.Add(new DataColumn("link", typeof(string))); 6 dr1 = dt.NewRow(); 7 dr1[0] = "Yahoo"; 8 dr1[1] = "http://www.yahoo.com"; 9 dt.Rows.Add(dr1); 10 dr2 = dt.NewRow(); 11 dr2[0] = "Google"; 12 dr2[1] = "http://www.google.com"; 13 dt.Rows.Add(dr2); 14 GridView GV = new GridView(); 15 GV.AutoGenerateColumns = false; 16 HyperLinkField hyp1 = new HyperLinkField(); 17 hyp1.HeaderText = "UsefulLinks"; 18 hyp1.DataTextField = "Text"; 19 hyp1.DataNavigateUrlFields = "link"; 20 hyp1.Target = "_blank"; 21 GV.Columns.Add(hyp1); 22 GV.DataSource = dt; 23 GV.DataBind(); 24 plhPlaceHolder.Controls.Add(GV);

              K Offline
              K Offline
              kubben
              wrote on last edited by
              #6

              So when you replace line 19 with string[] tmp = new string[1] {"link"}; hyp1.DataNavigateUrlFields = tmp; What error do you get? Ben

              F 1 Reply Last reply
              0
              • K kubben

                So when you replace line 19 with string[] tmp = new string[1] {"link"}; hyp1.DataNavigateUrlFields = tmp; What error do you get? Ben

                F Offline
                F Offline
                findtango
                wrote on last edited by
                #7

                Thank u Very much :rose: now it is working fine with some little change u really help me a lot in my code thanks a lot buddy :-D

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups