![]() |
|
|
|||||||
![]() |
ASP Net - how to handle the menu control, gridview, and postback...this is driving me nuts! |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
If anyone can help, I would very muchly appreciate it.
I have a main page that uses the .net 2.0 menu control with the multiview controls as the menu choices. This works fine. One of the menu choices dynamically loads a user control with a gridview (datagrid) control on it. That works fine. The problem arises when the user clicks on a different page of the gridview control---this is a paged gridview. When that happens, the gridview goes away. I'm assuming this is happening because the "OnPageIndexChanging" event is causing a postback and the user control doesn't feel like loading after that. I have tried all kinds of things to make this work.....loading the control at various stages (pageload, pagerender, etc)....to no avail. It just won't work for me. I would appreciate any help in solving this. I am beyond giving up on it as well. Relevant code is below: masterpage.aspx ------------------------------- <%@ Page Language="C#" %> <%@ Register TagPrefix="rgp" TagName="showTickets" Src="showTickets.ascx" %> string strDBView; protected void Page_Load(object sender, EventArgs e) { string strMenuLabel; if (!IsPostBack) { for (int index = 0; index < mvTicketMan.Views.Count; index++) { strMenuLabel = mvTicketMan.Views[index].ID.ToString().Replace("vw", "").Replace("_", " "); mnuTicketMan.Items.Add(new MenuItem(strMenuLabel, index.ToString())); } mnuTicketMan.Items[0].Selected = true; } } protected void mnuTicketMan_MenuItemClick(object sender, MenuEventArgs e) { Control ctrlShowTickets; mvTicketMan.ActiveViewIndex = Int32.Parse(e.Item.Value); strDBView = mvTicketMan.Views[Int32.Parse(e.Item.Value)].ID.ToString().Replace("vw", "").Replace("_", " "); if (strDBView == "My Tickets") { ctrlShowTickets = LoadControl("showTickets.ascx"); plhShowTickets.Controls.Add(ctrlShowTickets); //((showTickets)ctrlShowTickets).DBView = strDBView; //((showTickets)ctrlShowTickets).BindDataGrid("Ticke t_Number"); } } <asp:Menu ID="mnuTicketMan" Width="100%" runat="server" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False" OnMenuItemClick="mnuTicketMan_MenuItemClick"> <StaticMenuItemStyle CssClass=MenuCell ItemSpacing=0px /> <StaticHoverStyle CssClass=MenuCellHover /> <StaticSelectedStyle CssClass=MenuCellSelected ItemSpacing=0px /> </asp:Menu> <asp:MultiView ID="mvTicketMan" runat="server" ActiveViewIndex="0"> <%--New Ticket--%> <asp:View ID="vwCreate_Ticket" runat="server"> <table width="100%" height="100%" cellpadding=0 cellspacing=0> <tr> <td class="Canvas"> <rgp:createTicket ID="rgpCreateTicket" runat="server" /> </td> </tr> </table> </asp:View> <%--End New Ticket--%> <%--My Tickets--%> <asp:View ID="vwMy_Tickets" runat="server" > <table width="100%" height="100%" cellpadding=0 cellspacing=0> <tr> <td class="Canvas"> <asp <%-- <rgp:showTickets ID="rgpShowTickets" runat="server" /> --%> </td> </tr> </table> </asp:View> <%--End My Tickets--%> </asp:MultiView> ------------------------------- usercontrol ------------------------------- <%@ Control Language="C#" ClassName="showTickets" Debug="true" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="MySql.Data.MySqlClient" %> <script runat="server"> MySqlConnection conMain; // main db connector string strSortDirection; // toggles the sort direction // functions protected void Page_PreRender(object sender, EventArgs e) { } public void Page_Load(Object source, EventArgs e) { conMain = new MySqlConnection("db_connection_goes_here"); if (this.IsPostBack) { //BindDataGrid("Ticket_Number"); } } public void BindDataGrid(string strSortField) { strSortDirection = "DESC"; string sql = "sql stuff here"; conMain.Open(); MySqlDataAdapter ad = new MySqlDataAdapter(sql, conMain); DataSet ds = new DataSet(); ad.Fill(ds); grdTickets.DataSource = ds; grdTickets.DataBind(); conMain.Close(); } public void grdTickets_PageIndexChanged(Object source, GridViewPageEventArgs e) { grdTickets.PageIndex = e.NewPageIndex; BindDataGrid("Ticket_Number"); } </script> <asp:GridView ID="grdTickets" runat="server" AllowPaging="true" OnPageIndexChanging="grdTickets_PageIndexChanged" PageSize="15" > <AlternatingRowStyle BackColor="Silver" /> </asp:GridView> ------------------------------- John Smith |
|
|