How to change the data in a asp gridlist on click with UserControls?

35 views Asked by At

I'm trying to change the data of my gridlist on my homepage when you click on a button.. Tried many things nothing works. When I press the button to change gridview data nothing happpens and few secons later I get a error

How it looks: http://prntscr.com/7fa9qh The Error : http://prntscr.com/7faam0

I have left some code out to make it not all to big, like I only have 2 buttons in code but there are more

list.aspx.cs :

 protected void Page_Load(object sender, EventArgs e) {
        GvTop2000 usercontrol = (GvTop2000)Page.LoadControl("~/Pages /Usercontrols/ListGv/GvTop2000.ascx");
        pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
    }

    protected void btnTop2000_Click(object sender, EventArgs e) {
        pnlGVList.ContentTemplateContainer.Controls.Clear();
        GvTop2000 usercontrol = (GvTop2000)Page.LoadControl("~/Pages/Usercontrols/ListGv/GvTop2000.ascx");
        pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
        pnlGVList.Update();
    }

    protected void btnNieuw_Click(object sender, EventArgs e) {
        pnlGVList.ContentTemplateContainer.Controls.Clear();
        GvNieuw usercontrol = (GvNieuw)Page.LoadControl("~/Pages/Usercontrols/ListGv/GvNieuw.ascx");
        pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
        pnlGVList.Update();
    }

list.aspx :

<asp:Content ID="ContentHolderDD" runat="server"  ContentPlaceHolderID="ContentHolderDD">
<asp:ScriptManagerProxy ID="smProxy" runat="server" />
<%-- Year selector --%>
<asp:DropDownList ID="ddlJaar" CssClass="ddl" runat="server"  DataSourceID="DSYears" DataTextField="top2000jaar"  DataValueField="top2000jaar" AutoPostBack="True" />
<asp:SqlDataSource runat="server" ID="DSYears" ConnectionString='<%$  ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>'  SelectCommand="sp_get_year" SelectCommandType="StoredProcedure" />
</asp:Content>

<asp:Content ID="ContentPlaceholderButtons" runat="server"   ContentPlaceHolderID="ContentPlaceholderButtons">

gvTop2000 usercontrol:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GvTop2000.ascx.cs" Inherits="Top2000.Pages.Usercontrols.ListGv.GvTop2000" %>

<asp:GridView runat="server" ID="gridList" CellPadding="10" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataSourceID="DSList" AllowPaging="True" PageSize="100" CssClass="GridListings">


<Columns>
    <asp:BoundField DataField="positie" HeaderText="Positie" SortExpression="positie"></asp:BoundField>
    <asp:HyperLinkField DataNavigateUrlFields="artiestid" DataNavigateUrlFormatString="Artists.aspx?id={0}" DataTextField="naam" HeaderText="Artiest" />
    <asp:HyperLinkField DataNavigateUrlFields="songid" DataNavigateUrlFormatString="Song.aspx?id={0}" DataTextField="titel" HeaderText="Titel" />
    <asp:BoundField DataField="jaar" HeaderText="Jaar" SortExpression="jaar"></asp:BoundField>
</Columns>

</asp:GridView>

<asp:SqlDataSource runat="server" ID="DSList" ConnectionString='<%$   ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>' SelectCommand="sp_top2000_year" SelectCommandType="StoredProcedure" >
<SelectParameters>
    <asp:ControlParameter PropertyName="SelectedValue" DefaultValue=""   Name="YEAR" Type="Int32" ControlID="ContentHolderDD$ddlJaar" />
</SelectParameters>
</asp:SqlDataSource>
<asp:UpdatePanel runat="server" ID="pnlCButtons">
    <ContentTemplate>
        <asp:Button ID="btnTop2000" runat="server" Text="Top2000" OnClick="btnTop2000_Click" />
        <asp:Button ID="btnNieuw" runat="server" Text="Nieuw" OnClick="btnNieuw_Click" />
    </ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

<asp:Content id="ContentPlaceHolder1" runat="server"   ContentPlaceHolderID="ContentPlaceHolder1">

<%-- GridView --%>
<asp:UpdatePanel ID="pnlGVList" runat="server">
    <ContentTemplate>
        <asp:PlaceHolder runat="server" ID="phGv"/>
    </ContentTemplate>
</asp:UpdatePanel>

gvNieuw usercontrol :

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GvNieuw.ascx.cs" Inherits="Top2000.Pages.Usercontrols.ListGv.GvNieuw" %>
<asp:GridView runat="server" ID="gridList" CellPadding="10" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataSourceID="sqlDS" AllowPaging="True" PageSize="100"    CssClass="GridListings" DataKeyNames="songid,top2000jaar,songid1,artiestid1">

<Columns>
    <asp:BoundField DataField="songid" HeaderText="songid" SortExpression="songid" ReadOnly="True"></asp:BoundField>
    <asp:BoundField DataField="top2000jaar" HeaderText="top2000jaar" SortExpression="top2000jaar" ReadOnly="True"></asp:BoundField>
    <asp:BoundField DataField="positie" HeaderText="positie" SortExpression="positie" />
    <asp:BoundField DataField="songid1" HeaderText="songid1" InsertVisible="False" ReadOnly="True" SortExpression="songid1" />
    <asp:BoundField DataField="artiestid" HeaderText="artiestid" SortExpression="artiestid" />
    <asp:BoundField DataField="titel" HeaderText="titel" SortExpression="titel" />
    <asp:BoundField DataField="jaar" HeaderText="jaar" SortExpression="jaar" />
    <asp:BoundField DataField="artiestid1" HeaderText="artiestid1" InsertVisible="False" ReadOnly="True" SortExpression="artiestid1" />
    <asp:BoundField DataField="naam" HeaderText="naam" SortExpression="naam" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="sqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>" SelectCommand="sp_new_songs_year" SelectCommandType="StoredProcedure">
<SelectParameters>
    <asp:ControlParameter ControlID="ContentHolderDD$ddlJaar" Name="top2000Year" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
0

There are 0 answers