capella2007
02-08-2007, 03:38 PM
First, so you know what environment I'm working in, I have VS 2005 Pro, and I'm using VB code-behind pages.
The subject essentially describes my problem: I have a GridView and a FormView on a page and I want only the GridView to display on page load and the FormView to only show up when the user clicks a linkbutton, at which time the GridView "disappears".
I've tried messing with the visible properties of both the Grid- and FormViews, while at the same time changing the visible properties on the page load and button click events in the code-behind page:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim formview1 As New FormView
Dim gridview1 As New GridView
gridview1.Visible = True
formview1.Visible = False
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim gridview1 As New GridView
Dim linkbutton1 As New LinkButton
Dim formview1 As New FormView
GridView1.Visible = False
linkbutton1.Visible = False
formview1.Visible = True
End Sub
Here's the main, relevant parts of the Grid- and FormViews:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="2px" CellPadding="3"> </asp:GridView>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DefaultMode="Insert" DataSourceID="SqlDataSource1" DataKeyNames="id" Width="800px" BackColor="#DAE6E6">
</asp:FormView>
Here's some "testing" subs I've done:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Here I removed the "dim" statements altogether
gridview1.Visible = True
formview1.Visible = False
'Results in blue "squiggly" lines under the gridview1 and formview1 with the message: "Name gridview1 is not declared."
End Sub
'******************************
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Here I just removed the "new" keyword
Dim formview1 As FormView
Dim gridview1 As GridView
gridview1.Visible = True
formview1.Visible = False
'Results in green "squiggly" message under gridview1 & formview1 in second set of lines: "Variable gridview1 has been used before it has been assigned a value. A null reference exception could result at run time."
End Sub
Obviously, I've been working on this for a while now. The only way I've been able to "hide" and "unhide" the Grid and Formviews is with the Visible="true/false" on the aspx page.
The closest I've gotten is loading the page with the FormView not visible and the Gridview visible, but clicking on the linkbutton doesn't "hide" the GridView and "display" the FormView.
I suspect I'm missing something in the VB code, but can't quite figure it out. Someone in another forum suggested the "New" keyword in my vb code was "overriding" the visible= state I set on the aspx side. I know it can be done - I've done it myself before. I just can't find the code I used! Arrrgh!!
Any help would be greatly appreciated!
Thanks
The subject essentially describes my problem: I have a GridView and a FormView on a page and I want only the GridView to display on page load and the FormView to only show up when the user clicks a linkbutton, at which time the GridView "disappears".
I've tried messing with the visible properties of both the Grid- and FormViews, while at the same time changing the visible properties on the page load and button click events in the code-behind page:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim formview1 As New FormView
Dim gridview1 As New GridView
gridview1.Visible = True
formview1.Visible = False
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim gridview1 As New GridView
Dim linkbutton1 As New LinkButton
Dim formview1 As New FormView
GridView1.Visible = False
linkbutton1.Visible = False
formview1.Visible = True
End Sub
Here's the main, relevant parts of the Grid- and FormViews:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="2px" CellPadding="3"> </asp:GridView>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DefaultMode="Insert" DataSourceID="SqlDataSource1" DataKeyNames="id" Width="800px" BackColor="#DAE6E6">
</asp:FormView>
Here's some "testing" subs I've done:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Here I removed the "dim" statements altogether
gridview1.Visible = True
formview1.Visible = False
'Results in blue "squiggly" lines under the gridview1 and formview1 with the message: "Name gridview1 is not declared."
End Sub
'******************************
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Here I just removed the "new" keyword
Dim formview1 As FormView
Dim gridview1 As GridView
gridview1.Visible = True
formview1.Visible = False
'Results in green "squiggly" message under gridview1 & formview1 in second set of lines: "Variable gridview1 has been used before it has been assigned a value. A null reference exception could result at run time."
End Sub
Obviously, I've been working on this for a while now. The only way I've been able to "hide" and "unhide" the Grid and Formviews is with the Visible="true/false" on the aspx page.
The closest I've gotten is loading the page with the FormView not visible and the Gridview visible, but clicking on the linkbutton doesn't "hide" the GridView and "display" the FormView.
I suspect I'm missing something in the VB code, but can't quite figure it out. Someone in another forum suggested the "New" keyword in my vb code was "overriding" the visible= state I set on the aspx side. I know it can be done - I've done it myself before. I just can't find the code I used! Arrrgh!!
Any help would be greatly appreciated!
Thanks