problem with dynamic gridview Please help
-
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">
-
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">
Dim x As String() = New String(0) {} x(0) = "pid" lnk.DataNavigateUrlFields = x(0)
I didn't get any requirements for the signature
-
Dim x As String() = New String(0) {} x(0) = "pid" lnk.DataNavigateUrlFields = x(0)
I didn't get any requirements for the signature
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' -
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 mean if i coment this line
lnk.DataNavigateUrlFields = x(0)
it add that hyperlinkfield , but not passing the parameter.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
-
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'GridView1.DataKeyNames
gets the array of string so GridView1.DataKeyNames="pid" is wrong.lnk.DataNavigateUrlFields
is also gets the array of string solnk.DataNavigateUrlFields = x(0)
is wrong coz x(0) returns only string try this lnk.DataNavigateUrlFields=x Best regard Pathan---------------------------------------------------
-
GridView1.DataKeyNames
gets the array of string so GridView1.DataKeyNames="pid" is wrong.lnk.DataNavigateUrlFields
is also gets the array of string solnk.DataNavigateUrlFields = x(0)
is wrong coz x(0) returns only string try this lnk.DataNavigateUrlFields=x Best regard Pathan---------------------------------------------------