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
  1. Home
  2. Web Development
  3. ASP.NET
  4. problem with dynamic gridview Please help

problem with dynamic gridview Please help

Scheduled Pinned Locked Moved ASP.NET
helpcsssysadmindata-structures
7 Posts 3 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.
  • O Offline
    O Offline
    orsini
    wrote on last edited by
    #1

    Need help. I am trying to add a hyperlinkfield dynamically to a grid view , that works fine until i want to pass a parameter to the string, i get this error BC30311: Value of type 'String' cannot be converted to '1-dimensional array of String'. this is the code, Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load SqlDataSource1.SelectCommand = "SELECT * FROM [products]" GridView1.DataKeyNames = "pid" Dim lnk As HyperLinkField lnk = New HyperLinkField lnk.DataTextField = "pname" lnk.NavigateUrl = "home.aspx" lnk.DataNavigateUrlFields = "pid" End Sub < asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EnableViewState="false">

    T 1 Reply Last reply
    0
    • O orsini

      Need help. I am trying to add a hyperlinkfield dynamically to a grid view , that works fine until i want to pass a parameter to the string, i get this error BC30311: Value of type 'String' cannot be converted to '1-dimensional array of String'. this is the code, Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load SqlDataSource1.SelectCommand = "SELECT * FROM [products]" GridView1.DataKeyNames = "pid" Dim lnk As HyperLinkField lnk = New HyperLinkField lnk.DataTextField = "pname" lnk.NavigateUrl = "home.aspx" lnk.DataNavigateUrlFields = "pid" End Sub < asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EnableViewState="false">

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      Dim x As String() = New String(0) {} x(0) = "pid" lnk.DataNavigateUrlFields = x(0)

      I didn't get any requirements for the signature

      O 1 Reply Last reply
      0
      • T ToddHileHoffer

        Dim x As String() = New String(0) {} x(0) = "pid" lnk.DataNavigateUrlFields = x(0)

        I didn't get any requirements for the signature

        O Offline
        O Offline
        orsini
        wrote on last edited by
        #3

        thank you so much for taking the time to answer, but still not working, i can't believe, i put the code this way Dim lnk As HyperLinkField lnk = New HyperLinkField lnk.DataTextField = "pname" lnk.NavigateUrl = "home.aspx" lnk.DataNavigateUrlFormatString = "~/home.aspx?pid={0}" Dim x As String() = New String(0) {} x(0) = "pid" lnk.DataNavigateUrlFields = x(0) and still, over the last line on x(0) still have the message that says value of type 'string'cannot be converted to '1 dimensional array of string'

        O I 2 Replies Last reply
        0
        • O orsini

          thank you so much for taking the time to answer, but still not working, i can't believe, i put the code this way Dim lnk As HyperLinkField lnk = New HyperLinkField lnk.DataTextField = "pname" lnk.NavigateUrl = "home.aspx" lnk.DataNavigateUrlFormatString = "~/home.aspx?pid={0}" Dim x As String() = New String(0) {} x(0) = "pid" lnk.DataNavigateUrlFields = x(0) and still, over the last line on x(0) still have the message that says value of type 'string'cannot be converted to '1 dimensional array of string'

          O Offline
          O Offline
          orsini
          wrote on last edited by
          #4

          i mean if i coment this line lnk.DataNavigateUrlFields = x(0) it add that hyperlinkfield , but not passing the parameter.

          T 1 Reply Last reply
          0
          • O orsini

            i mean if i coment this line lnk.DataNavigateUrlFields = x(0) it add that hyperlinkfield , but not passing the parameter.

            T Offline
            T Offline
            ToddHileHoffer
            wrote on last edited by
            #5

            lnk.DataNavigateUrlFields = x BTW, set option strction on set option explicit on It will force you to write better code.

            I didn't get any requirements for the signature

            1 Reply Last reply
            0
            • O orsini

              thank you so much for taking the time to answer, but still not working, i can't believe, i put the code this way Dim lnk As HyperLinkField lnk = New HyperLinkField lnk.DataTextField = "pname" lnk.NavigateUrl = "home.aspx" lnk.DataNavigateUrlFormatString = "~/home.aspx?pid={0}" Dim x As String() = New String(0) {} x(0) = "pid" lnk.DataNavigateUrlFields = x(0) and still, over the last line on x(0) still have the message that says value of type 'string'cannot be converted to '1 dimensional array of string'

              I Offline
              I Offline
              Imran Khan Pathan
              wrote on last edited by
              #6

              GridView1.DataKeyNames gets the array of string so GridView1.DataKeyNames="pid" is wrong. lnk.DataNavigateUrlFields is also gets the array of string so lnk.DataNavigateUrlFields = x(0) is wrong coz x(0) returns only string try this lnk.DataNavigateUrlFields=x Best regard Pathan

              ---------------------------------------------------

              O 1 Reply Last reply
              0
              • I Imran Khan Pathan

                GridView1.DataKeyNames gets the array of string so GridView1.DataKeyNames="pid" is wrong. lnk.DataNavigateUrlFields is also gets the array of string so lnk.DataNavigateUrlFields = x(0) is wrong coz x(0) returns only string try this lnk.DataNavigateUrlFields=x Best regard Pathan

                ---------------------------------------------------

                O Offline
                O Offline
                orsini
                wrote on last edited by
                #7

                Great, Now works perfectly, Thank you so much to both of you guys. I will follow your advice , once again thanks

                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