当我在内容占位符中使用它时,Gridview Paging无法正常工作?

时间:2014-02-23 21:51:48

标签: c# asp.net datagridview master-pages contentplaceholder

当我使用母版页时,我不知道为什么分页不起作用。如果我将相同的代码放在另一个未与母版页链接的文件中,它就像一个魅力。但是当我将它链接到母版页时,它不起作用。

这是我的标记

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

<div id="menu_content">
    <div class="tabs">
        My Addresses</div>
    <div class="midContent">
        <asp:GridView ID="addressGrd" OnPageIndexChanging="addressGrd_PageIndexChanging"
            Width="816px" ForeColor="#ffffff" AllowSorting="true" HeaderStyle-BackColor="#222222"
            HeaderStyle-Height="60px" runat="server" AutoGenerateColumns="False" GridLines="None"
            AllowPaging="True" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last"
            PagerSettings-Mode="NextPreviousFirstLast" PageSize="5" PagerSettings-PageButtonCount="4">
            <Columns>
                <asp:BoundField DataField="customerName" HeaderText="Name" ReadOnly="True" />
                <asp:BoundField DataField="customerCompany" HeaderText="Company" ReadOnly="True" />
                <asp:BoundField DataField="customerPhone" HeaderText="Phone" ReadOnly="True" />
                <asp:BoundField DataField="addressLine1" HeaderText="Address 1" ReadOnly="True" />
                <asp:BoundField DataField="addressLine2" HeaderText="Address 2" ReadOnly="True" />
                <asp:BoundField DataField="city" HeaderText="City" ReadOnly="True" />
                <asp:BoundField DataField="state" HeaderText="State" ReadOnly="True" />
                <asp:BoundField DataField="zipCode" HeaderText="Zip Code" ReadOnly="True" />
                  <asp:TemplateField>
                  <HeaderTemplate>
                                Main Address
                            </HeaderTemplate>
                            <ItemTemplate>                                    
                                <asp:ImageButton runat="server" OnClick="changeStatus" ID="imgStatus" CommandArgument='<%#Eval("mainAddress")+","+ Eval("addressID")%>'
                                    ImageUrl='<%# Bind_Image(Eval("mainAddress").ToString()) %>' />
                            </ItemTemplate>
                        </asp:TemplateField>                           
                        <asp:TemplateField>
                            <HeaderTemplate>
                                Action
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:LinkButton ID="editItem" Text="&nbsp; &nbsp; &nbsp;" OnClick="Edit" CommandArgument='<%# Eval("addressID")%>'
                                    CssClass="editButton" runat="server">                                       
                                </asp:LinkButton>
                                <asp:LinkButton Text="&nbsp; &nbsp; &nbsp;" ID="deleteItem" CssClass="deleteButton"
                                    runat="server" CommandArgument='<%# Eval("addressID")%>' OnClientClick="return confirm('Do You Want To Delete ?')"
                                    OnClick="Delete">                                        
                                </asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
            </Columns>


            <PagerSettings Mode="NumericFirstLast" PageButtonCount="4" FirstPageText="First"
                LastPageText="Last" />
            <PagerStyle BackColor="#222222" Height="30px" VerticalAlign="Bottom" HorizontalAlign="Center" />
            <RowStyle Height="50px" BackColor="#117186" />
            <AlternatingRowStyle BackColor="#0b4d5b" />
        </asp:GridView>
        <a href="AddAddresses.php5" style="text-decoration:none"><div style="float:right; margin-bottom:20px; margin-right:20px"><input type="button" class="buttonEffect" value="Register New Address" /></div></a>
    </div>
</div>

这是我背后的代码。

retrievedata3ct rd3ct;
DataTable dt;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
    rd3ct = new retrievedata3ct();
       dt = new DataTable();
       ds = new DataSet();


    if (!this.IsPostBack)
    {
        addAddresses();
    }

}

public void addAddresses()
{
    rd3ct = new retrievedata3ct();
    ds = new DataSet();
    ds = rd3ct.addressesSelection("", "");

    addressGrd.DataSource = ds.Tables[0];
    addressGrd.DataBind();
    addressGrd.Visible = true;

    //ScriptManager.GetCurrent(this).RegisterPostBackControl(addressGrd);
}

public string Bind_Image(string Status)
{
    bool status = Convert.ToBoolean(Status);

    if (status)
    {
        return "adminCP/resources/images/icons/tick_circle.png";
    }
    else
    {
        return "adminCP/resources/images/icons/cross_circle.png";
    }
}

protected void addressGrd_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    addressGrd.PageIndex = e.NewPageIndex;
    addAddresses();
}

protected void Delete(object sender, EventArgs e)
{

    LinkButton lnkRemove = (LinkButton)sender;
    string ds = "";
    ds = rd3ct.addressesDeletion(lnkRemove.CommandArgument);

    if (ds == "OK")
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Record Deleted.');", true);
        addAddresses();
    }
    else
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error Occurred.');", true);
    }
}


protected void Edit(object sender, EventArgs e)
{

    LinkButton lnkRemove = (LinkButton)sender;
    Session["addressID"] = "";
    Session["addressID"] = lnkRemove.CommandArgument;

    Response.Redirect("editAddresses.php5", false);
}   

protected void changeStatus(object sender, EventArgs e)
{
    string ds = "";
    ImageButton ib = (ImageButton)sender;

    string[] commandArgs = ib.CommandArgument.ToString().Split(new char[] { ',' });
    string status = commandArgs[0];
    string id = commandArgs[1];

    if (status == "True")
    {
        ds = rd3ct.addressesStatusUpdate(id, "False");
        if (ds == "OK")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Status Disabled.');", true);
            addAddresses();
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error Occurred.');", true);
        }
    }
    else
    {
        ds = rd3ct.addressesStatusUpdate(id, "True");
        if (ds == "OK")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Status Enabled.');", true);
            addAddresses();
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error Occurred.');", true);
        }
    }



}   

请帮帮我。任何帮助都将受到高度赞赏。

2 个答案:

答案 0 :(得分:0)

您是否尝试创建一个空母版页以将内容放入?我怀疑你的母版页打破了GridView。

答案 1 :(得分:0)

解决了问题。

实际上网格视图中的按钮名称是冲突的。

我有一个按钮,其ID是“提交”,而在我的另一个页面中,还有一个名为相同ID的按钮。这就是为什么gridview分页不起作用。

R.I.P Coding ..:)