Gridview not appearing between views in multiviewhttp://forums.asp.net/t/1798532.aspx/1?Gridview+not+appearing+between+views+in+multiviewWed, 02 May 2012 02:44:20 -040017985324958517http://forums.asp.net/p/1798532/4958517.aspx/1?Gridview+not+appearing+between+views+in+multiviewGridview not appearing between views in multiview <p>Hi,</p> <p>&nbsp;&nbsp; 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.</p> <p>Thanks!</p> 2012-04-30T15:36:28-04:004958523http://forums.asp.net/p/1798532/4958523.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>As you change to different multiviews, make sure you do a databind each time.</p> 2012-04-30T15:39:13-04:004958539http://forums.asp.net/p/1798532/4958539.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>Thanks for the reply. How to do that? Again do i need to call the function that loads the dataset and do the databinding?</p> 2012-04-30T15:45:20-04:004958548http://forums.asp.net/p/1798532/4958548.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>Kind of like this to repopulate your gridview from codebehind.&nbsp;</p> <p>GridView1.DataBind()</p> 2012-04-30T15:51:00-04:004958560http://forums.asp.net/p/1798532/4958560.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>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</p> 2012-04-30T15:56:31-04:004958584http://forums.asp.net/p/1798532/4958584.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>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.</p> <p></p> <p>Thanks!</p> 2012-04-30T16:17:43-04:004958588http://forums.asp.net/p/1798532/4958588.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>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.</p> <p><a href="http://forums.asp.net/t/1741010.aspx/1?Paging&#43;through&#43;gridview&#43;clears&#43;selected&#43;checkboxes">http://forums.asp.net/t/1741010.aspx/1?Paging&#43;through&#43;gridview&#43;clears&#43;selected&#43;checkboxes</a></p> 2012-04-30T16:21:52-04:004958605http://forums.asp.net/p/1798532/4958605.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>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!</p> 2012-04-30T16:38:48-04:004958608http://forums.asp.net/p/1798532/4958608.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>That sounds like the behavior. Chances are your app may be doing a postback as it goes from view1 to view2.</p> 2012-04-30T16:40:24-04:004960716http://forums.asp.net/p/1798532/4960716.aspx/1?Re+Gridview+not+appearing+between+views+in+multiviewRe: Gridview not appearing between views in multiview <p>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.</p> <p>Default.aspx:</p> <pre class="prettyprint">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:MultiView ID=&quot;MultiView1&quot; runat=&quot;server&quot; ActiveViewIndex=&quot;0&quot;&gt; &lt;asp:View ID=&quot;View1&quot; runat=&quot;server&quot;&gt; &lt;asp:TextBox ID=&quot;TextBox1&quot; runat=&quot;server&quot;&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Button&quot; onclick=&quot;Button1_Click&quot; /&gt;&lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text=&quot;View1&quot;&gt;&lt;/asp:Label&gt; &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; DataKeyNames=&quot;UserName&quot;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&quot;UserID&quot; HeaderText=&quot;UserID&quot; InsertVisible=&quot;False&quot; ReadOnly=&quot;True&quot; SortExpression=&quot;UserID&quot; /&gt; &lt;asp:BoundField DataField=&quot;UserName&quot; HeaderText=&quot;UserName&quot; ReadOnly=&quot;True&quot; SortExpression=&quot;UserName&quot; /&gt; &lt;asp:BoundField DataField=&quot;RealName&quot; HeaderText=&quot;RealName&quot; SortExpression=&quot;RealName&quot; /&gt; &lt;asp:BoundField DataField=&quot;Age&quot; HeaderText=&quot;Age&quot; SortExpression=&quot;Age&quot; /&gt; &lt;asp:CheckBoxField DataField=&quot;Sex&quot; HeaderText=&quot;Sex&quot; SortExpression=&quot;Sex&quot; /&gt; &lt;asp:BoundField DataField=&quot;Mobile&quot; HeaderText=&quot;Mobile&quot; SortExpression=&quot;Mobile&quot; /&gt; &lt;asp:BoundField DataField=&quot;Phone&quot; HeaderText=&quot;Phone&quot; SortExpression=&quot;Phone&quot; /&gt; &lt;asp:BoundField DataField=&quot;Email&quot; HeaderText=&quot;Email&quot; SortExpression=&quot;Email&quot; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:Button ID=&quot;Button3&quot; runat=&quot;server&quot; Text=&quot;ShowView2&quot; onclick=&quot;Button3_Click&quot; /&gt; &lt;/asp:View&gt; &lt;asp:View ID=&quot;View2&quot; runat=&quot;server&quot;&gt; &lt;asp:TextBox ID=&quot;TextBox2&quot; runat=&quot;server&quot;&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID=&quot;Button2&quot; runat=&quot;server&quot; Text=&quot;ShowView1&quot; onclick=&quot;Button2_Click&quot; /&gt;&lt;asp:Label ID=&quot;Label2&quot; runat=&quot;server&quot; Text=&quot;View2&quot;&gt;&lt;/asp:Label&gt; &lt;/asp:View&gt; &lt;/asp:MultiView&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p>Default.aspx.cs:</p> <pre class="prettyprint">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; } </pre> <p>Additionally, please paste your codes here for analysis.</p> 2012-05-02T02:44:20-04:00