I have a multiview and have 2 views inside it. In view1 i search by name and a gridview appears based on the search. I click on the link button inside the gridview and i activate view2 and i show the results. I have a back button in view2 and i set activeviewindex=0
referring to view1 and i dont see the gridview which i saw earlier. I am just seeing the textbox where i entered the name and button to search but not the gridview. What would be the issue. I just say multivew1.activeviewindex = 0 but no gridview.
I tried it but the gridview does not appear. So all the datasource will be there when i come back to the previous view? because i do not have gridview.datasource = dataset. All i have in the backbutton click event is gridview.databind() as you said, multiview.activeviewindex
= 0
Just another question related to this topic, even the textbox value is not maintained between views. when i click on back button there is no value in the textbox either. why is that.
The problem you are having is your application is not maintaining session state. I recently had to do some major fanagling to maintain checkbox state using a control as I would go back and forth between pages. Take a look at this thread as it might give
you some clues on how to maintain your gridview stuff.
OK. Is this scenario(for checkbox control) applies to textbox control too? Because when i comeback to view1 from view2, the values in the textbox is cleared!
Hi, I tested on my computer, found the status of the Textbox and GridView persist. Please make sure “ViewStateMode” attribute in @ Page directive is “Enabled”. I made a simple example, you can refer to it.
RGRajan
Member
44 Points
44 Posts
Gridview not appearing between views in multiview
Apr 30, 2012 03:36 PM|LINK
Hi,
I have a multiview and have 2 views inside it. In view1 i search by name and a gridview appears based on the search. I click on the link button inside the gridview and i activate view2 and i show the results. I have a back button in view2 and i set activeviewindex=0 referring to view1 and i dont see the gridview which i saw earlier. I am just seeing the textbox where i entered the name and button to search but not the gridview. What would be the issue. I just say multivew1.activeviewindex = 0 but no gridview.
Thanks!
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: Gridview not appearing between views in multiview
Apr 30, 2012 03:39 PM|LINK
As you change to different multiviews, make sure you do a databind each time.
RGRajan
Member
44 Points
44 Posts
Re: Gridview not appearing between views in multiview
Apr 30, 2012 03:45 PM|LINK
Thanks for the reply. How to do that? Again do i need to call the function that loads the dataset and do the databinding?
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: Gridview not appearing between views in multiview
Apr 30, 2012 03:51 PM|LINK
Kind of like this to repopulate your gridview from codebehind.
GridView1.DataBind()
RGRajan
Member
44 Points
44 Posts
Re: Gridview not appearing between views in multiview
Apr 30, 2012 03:56 PM|LINK
I tried it but the gridview does not appear. So all the datasource will be there when i come back to the previous view? because i do not have gridview.datasource = dataset. All i have in the backbutton click event is gridview.databind() as you said, multiview.activeviewindex = 0
RGRajan
Member
44 Points
44 Posts
Re: Gridview not appearing between views in multiview
Apr 30, 2012 04:17 PM|LINK
Just another question related to this topic, even the textbox value is not maintained between views. when i click on back button there is no value in the textbox either. why is that.
Thanks!
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: Gridview not appearing between views in multiview
Apr 30, 2012 04:21 PM|LINK
The problem you are having is your application is not maintaining session state. I recently had to do some major fanagling to maintain checkbox state using a control as I would go back and forth between pages. Take a look at this thread as it might give you some clues on how to maintain your gridview stuff.
http://forums.asp.net/t/1741010.aspx/1?Paging+through+gridview+clears+selected+checkboxes
RGRajan
Member
44 Points
44 Posts
Re: Gridview not appearing between views in multiview
Apr 30, 2012 04:38 PM|LINK
OK. Is this scenario(for checkbox control) applies to textbox control too? Because when i comeback to view1 from view2, the values in the textbox is cleared!
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: Gridview not appearing between views in multiview
Apr 30, 2012 04:40 PM|LINK
That sounds like the behavior. Chances are your app may be doing a postback as it goes from view1 to view2.
Allen Li - M...
Star
10411 Points
1196 Posts
Re: Gridview not appearing between views in multiview
May 02, 2012 02:44 AM|LINK
Hi, I tested on my computer, found the status of the Textbox and GridView persist. Please make sure “ViewStateMode” attribute in @ Page directive is “Enabled”. I made a simple example, you can refer to it.
Default.aspx:
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> <asp:View ID="View1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><asp:Label ID="Label1" runat="server" Text="View1"></asp:Label> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserName"> <Columns> <asp:BoundField DataField="UserID" HeaderText="UserID" InsertVisible="False" ReadOnly="True" SortExpression="UserID" /> <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName" /> <asp:BoundField DataField="RealName" HeaderText="RealName" SortExpression="RealName" /> <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" /> <asp:CheckBoxField DataField="Sex" HeaderText="Sex" SortExpression="Sex" /> <asp:BoundField DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" /> <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" /> <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /> </Columns> </asp:GridView> <asp:Button ID="Button3" runat="server" Text="ShowView2" onclick="Button3_Click" /> </asp:View> <asp:View ID="View2" runat="server"> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button2" runat="server" Text="ShowView1" onclick="Button2_Click" /><asp:Label ID="Label2" runat="server" Text="View2"></asp:Label> </asp:View> </asp:MultiView> </div> </form> </body> </html>Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { DataBindGridView(); } protected void Button2_Click(object sender, EventArgs e) { this.MultiView1.ActiveViewIndex = 0; } // Please modify your own SQL sentence here: private void DataBindGridView() { string connectionString = WebConfigurationManager.ConnectionStrings["ASPNETSTUDYConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); SqlCommand comd = conn.CreateCommand(); comd.CommandText = "select * from UserInfo where UserID=@UserID"; int UserID = Int32.Parse(this.TextBox1.Text); comd.Parameters.AddWithValue("@UserID", UserID); try { DataTable table = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(comd); adapter.Fill(table); this.GridView1.DataSource = table; this.GridView1.DataBind(); } catch (Exception) { } finally { } } protected void Button3_Click(object sender, EventArgs e) { this.MultiView1.ActiveViewIndex = 1; }Additionally, please paste your codes here for analysis.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework