c# - How to hide a single formview row -
im trying hide single row of formview based on current state of session variable.
currently attempting encase row in update panel set visible property true or false.
this isnt working.
here code:
<asp:formview id="formview1" runat="server" height="51px" width="387px"> <edititemtemplate> coffeename: <asp:textbox id="coffeenametextbox" runat="server" text='<%# bind("coffeename") %>' /> <br /> coffeeorigin: <asp:textbox id="coffeeorigintextbox" runat="server" text='<%# bind("coffeeorigin") %>' /> <br /> coffeestrength: <asp:textbox id="coffeestrengthtextbox" runat="server" text='<%# bind("coffeestrength") %>' /> <br /> coffeeprice: <asp:textbox id="coffeepricetextbox" runat="server" text='<%# bind("coffeeprice") %>' /> <br /> coffeegrind: <asp:textbox id="coffeegrindtextbox" runat="server" text='<%# bind("coffeegrind") %>' /> <br /> coffeeqty: <asp:textbox id="coffeeqtytextbox" runat="server" text='<%# bind("coffeeqty") %>' /> <br /> coffeerrp: <asp:textbox id="coffeerrptextbox" runat="server" text='<%# bind("coffeerrp") %>' /> <br /> <asp:linkbutton id="updatebutton" runat="server" causesvalidation="true" commandname="update" text="update" /> <asp:linkbutton id="updatecancelbutton" runat="server" causesvalidation="false" commandname="cancel" text="cancel" /> </edititemtemplate> <itemtemplate> <b>origin:</b> <asp:label id="coffeeoriginlabel" runat="server" text='<%# bind("coffeeorigin") %>' /> <br /> <br /> <b>grind:</b> <asp:label id="coffeegrindlabel" runat="server" text='<%# bind("coffeegrind") %>' /> <br /> <br /> <b>strength:</b> <asp:label id="coffeestrengthlabel" runat="server" text='<%# bind("coffeestrength") %>' /> <br /> <br /> <b>price: £</b> <asp:label id="coffeepricelabel" runat="server" text='<%# bind("coffeeprice") %>' /> <br /> <br /> ********** panel used enclose stock level********** <asp:panel id="panellevel" runat="server"> <b>stock level:</b> <asp:label id="coffeeqtylabel" runat="server" text='<%# bind("coffeeqty") %>' /> <br /> <br /> <br /> </asp:panel> </itemtemplate> </asp:formview>
what im trying achieve.
current formview:
setting panel visibility false should produce following output:
could give more code? where's updatepanel? how set row visibility?
try this, worked me:
code cs:
protected void page_load(object sender, eventargs e) { if (!ispostback) { bindformview(); } } private void bindformview() { datatable dt = new datatable(); dt.columns.add("coffeename", typeof(string)); dt.columns.add("coffeeorigin", typeof(string)); dt.columns.add("coffeestrength", typeof(int)); dt.columns.add("coffeeprice", typeof(double)); dt.columns.add("coffeegrind", typeof(string)); dt.columns.add("coffeeqty", typeof(int)); dt.columns.add("coffeerrp", typeof(int)); datarow dr = dt.newrow(); dr["coffeename"] = "kenya"; dr["coffeeorigin"] = "smooth"; dr["coffeestrength"] = 6; dr["coffeeprice"] = 2.99; dr["coffeegrind"] = "kenya"; dr["coffeeqty"] = 6; dt.rows.add(dr); formview1.datasource = dt; formview1.databind(); } protected void btnhiderow_click(object sender, eventargs e) { session["hiderow"] = session["hiderow"] == null ? false : (bool)session["hiderow"]; bindformview(); } protected void formview1_databound(object sender, eventargs e) { if (session["hiderow"] != null) { var pnltohide = formview1.findcontrol("panellevel"); pnltohide.visible = (bool)session["hiderow"]; } }
Comments
Post a Comment