ASP.net make Buttons set GridView Visible property to True or False -


i have asp.net web page has 2 gridviews. have 2 buttons want able click 1 make 1 gridview visible , other hidden, , other button make first gridview hidden , 2nd gridview visible. when click either of them nothing happens. i've played around gridview visible settings w/ no luck.i'm sure simple. looking! code below:

the 2 gridviews:

<asp:gridview id="gridshowusers" runat="server" autogeneratecolumns="false" datakeynames="user_id" datasourceid="sqldatasource1" allowpaging="true">         <columns>             <asp:commandfield showdeletebutton="true" showeditbutton="true" />             <asp:boundfield datafield="user_id" headertext="user id" insertvisible="false" readonly="true" sortexpression="user_id" />             <asp:boundfield datafield="user_name" headertext="username" sortexpression="user_name" />             <asp:boundfield datafield="user_password" headertext="password" sortexpression="user_password" />             <asp:boundfield datafield="user_securitylevel" headertext="security level" sortexpression="user_securitylevel" />         </columns>     </asp:gridview>  <asp:gridview id="gridorders" runat="server" allowsorting="true" autogeneratecolumns="false" datakeynames="ordr_id" datasourceid="sqldatasource2" emptydatatext="there no orders display" allowpaging="true">         <columns>             <asp:commandfield showdeletebutton="true" showeditbutton="true" showselectbutton="true" />             <asp:boundfield datafield="ordr_id" headertext="ordr_id" insertvisible="false" readonly="true" sortexpression="ordr_id" />             <asp:boundfield datafield="ordr_date" headertext="ordr_date" sortexpression="ordr_date" />             <asp:boundfield datafield="ordr_fname" headertext="ordr_fname" sortexpression="ordr_fname" />             <asp:boundfield datafield="ordr_lname" headertext="ordr_lname" sortexpression="ordr_lname" />             <asp:boundfield datafield="ordr_streetaddress" headertext="ordr_streetaddress" sortexpression="ordr_streetaddress" />             <asp:boundfield datafield="ordr_city" headertext="ordr_city" sortexpression="ordr_city" />             <asp:boundfield datafield="ordr_state" headertext="ordr_state" sortexpression="ordr_state" />             <asp:boundfield datafield="ordr_zipcode" headertext="ordr_zipcode" sortexpression="ordr_zipcode" />         </columns>     </asp:gridview> 

code behind buttons:

protected void btnshowusers_click(object sender, eventargs e) {     gridshowusers.visible = true;     gridorders.visible = false; }  protected void btnshoworders_click(object sender, eventargs e) {     gridshowusers.visible = false;     gridorders.visible = true; } 

basically code should work, maybe wrong overall context. please provide code of buttons, , maybe full page code - or stuff maybe in updatepanels?


anyway, have happen via postback, meaning in c#-code? otherwise propose use client side solutions, f.e. jquery or javascript.

in jquery (assuming button ids):

$("#btnshowusers").on("click", function(){   $("#gridshowusers").show();   $("#gridorders").hide(); });  $("#btnshoworders").on("click", function(){   $("#gridshowusers").hide();   $("#gridorders").show(); }); 

this enables fancy stuff animations (try .hide(500)) or use functions toggle(), , doesn't cause postback , therefore doesn't reload whole page.

don't forget add lates stable jquery library asp.net -section (https://developers.google.com/speed/libraries/#jquery):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>  

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -