473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

problem with user control containing GridView control and paging...

ASP.Net 2.0 / C# / IIS 6

I have 2 pages. The master page consists of a tabbed menu created using the
Menu and MultiView controls. Something like this:

http://fredrik.nsquared2.com/viewpos...wfeedback=true

The second page is a user control that contains a GridView control linked to
a database table. What's supposed to happen is that the user clicks on a
menu choice and an appropriate user control will load. For example, if one
of the menu choices is "User Data", the GridView will connect to the
database and show the appropriate data. No problem there. I have the
GridView set for paging up to 15 records per page. When I load the user
control at design time (i.e. <myControl:dataGrid id="blah" runat="server"
/>), everything seems to work fine.

However, I need to dynamically load the controls at run-time based on a menu
choice. This is what is driving me bonkers. What happens now is that the
datagrid won't bind. If I call the databinding function outside of the
!IsPostBack if-clause, it will show the data. But when you click on the
next page, the GridView goes away. I have tried everything I could think
of. What am I missing?

Below is the relevant code. I appreciate any suggestions!!!!!!!! Like I
said, if I load the control at design time, the app works like a charm. But
if I load it as needed, it doesn't work right. Hopefully, you will
understand what I'm trying to do.

When I do it like this, it works:
master.aspx
<script>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
for (int index = 0; index < mvttMan.Views.Count; index++)
{
strMenuLabel = mvttMan.Views[index].ID.ToString().Replace("vw",
"").Replace("_", " ");
mnuttMan.Items.Add(new MenuItem(strMenuLabel,
index.ToString()));
}
mnuttMan.Items[0].Selected = true;
}
}

protected void mnuttMan_MenuItemClick(object sender, MenuEventArgs e)
{
mvttMan.ActiveViewIndex = Int32.Parse(e.Item.Value);
}
</script>

<asp:Menu ID="mnuttMan" Width="100%" runat="server"
OnMenuItemClick="mnuttMan_MenuItemClick">
<asp:MultiView ID="mvttMan" runat="server" ActiveViewIndex="0">

<asp:View ID="vwMy_Choice" runat="server" >
<cnt:showtts ID="cntShowtts" runat="server" / <----it
works like this
</asp:View>
</asp:MultiView>
........................................
But if I do it like this, it fails:
master.aspx
// code mostly the same above...just loading the control at design time and
binding to a placeholder
protected void mnuttMan_MenuItemClick(object sender, MenuEventArgs e)
{
string strDBView;

mvttMan.ActiveViewIndex = Int32.Parse(e.Item.Value);
strDBView =
mvttMan.Views[Int32.Parse(e.Item.Value)].ID.ToString().Replace("vw",
"").Replace("_", " ");

if (strDBView == "My Choice")
{
ctlShowtts = LoadControl("incs/Showtts.ascx");
plhShowtts.Controls.Add(ctlShowtts);
}
}

<asp:View ID="vwMy_tts" runat="server" >
<asp:PlaceHolder ID="plhShowtts" runat="server" />
</asp:View>

Okay, and the code for the user control is as follows:
usercontrol.ascx
<script runat="server">

MySqlConnection conMain;
string strSortDirection;

public void Page_Load(Object source, EventArgs e)
{
conMain = new MySqlConnection("connection");

//BindDataGrid("Ticket_Number"); //if I uncomment this, it will
obviously show data on first load but nothing afterwards

if (!this.IsPostBack)
{
BindDataGrid(); // this doesn't appear to be happening when I
load the control dynamically
}
}

public void BindDataGrid()
{
string sql = "sql goes here";

conMain.Open();
MySqlDataAdapter ad = new MySqlDataAdapter(sql, conMain);
DataSet ds = new DataSet();

ad.Fill(ds);

grdDB.DataSource = ds;
grdDB.DataBind();
conMain.Close();
}

public void grdDB_PageIndexChanged(Object source, GridViewPageEventArgs
e)
{
grdDB.PageIndex = e.NewPageIndex;
BindDataGrid();
}
</script>

<asp:GridView ID="grdDB" runat="server" AllowPaging="true"
OnPageIndexChanging="grdDB_PageIndexChanged" PageSize="15">
<AlternatingRowStyle BackColor="Silver" />
</asp:GridView>

................The End....................


Aug 2 '06 #1
0 2342

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Random | last post by:
I'm playing around with the GridView control in ASP.NET 2.0, and I'm binding the control to an XML data source. I'm trying to implement paging, but am getting an error when I click on the link to...
5
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records...
2
by: WebBuilder451 | last post by:
I have a grid view and filter it based on an event from another control. I set the filter and it works fine, but when i page it reverts back to the full set of data from the datasource. How can i...
4
by: Chuck | last post by:
I'm setting the column with for a gridview (25+- columns) and have paging turned on. When the gridview is first displayed, the column widths are all set to the default. But after paging to...
2
by: Jeff | last post by:
Hey ASP.NET 2.0 GridView have AllowPaging & PageSize for the letting the GridView span multiple pages. But is the same allowed on a Repeater control? I didn't see any properties like...
0
by: webaccess | last post by:
Hi Friends ..!! I want to use datagrid/dataview control to data in tablular format,also I want to add paging and format the data of table column. Problem is data is coming from API Dom in as...
1
by: suganya | last post by:
I have displayed the data from the DB to the GridView made a column in the GridView as HyperLink allowed paging by setting the Allow Paging Property to "True". By clicking on the page no link I have...
1
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of...
0
by: Jeff | last post by:
hi there ;) asp.net 2.0 I'm having problem with paging in GridView, I'm using custom paging. The ObjectDataSource reads in the rows needed for displaying each page as each page is selected....
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.