分页不适用于显示第一个GridView详细信息的第二个GridView

时间:2016-12-09 11:24:01

标签: c# asp.net gridview

我想要你的帮助。 我有一个显示一些数据的Gridview,当我选择一行时,所选行的详细信息将在另一个Gridview中,但是分页不在第二个Gridview中工作!

注意:每个gridview都在视图中

例如:

        <asp:MultiView ID="MultiView" runat="server" ActiveViewIndex="0">
            <asp:View ID="View_1" runat="server">
                <asp:GridView runat="server" ID="GridView_1"
                    ItemType="myApp.Models.DTO"
                    SelectMethod="GridView_1_GetData"
                    OnRowCommand="GridView_1_RowCommand"
                    AutoGenerateColumns="False"
                    AllowPaging="true">
                    <Columns>
                        <asp:BoundField DataField="id_prof" HeaderText="ID" />
                        <asp:BoundField DataField="name" HeaderText="Name" />
                        <asp:BoundField DataField="lname" HeaderText="Last Name" />
                        <asp:ButtonField CommandName="Select" Text="Details.." HeaderText="Details" />
                    </Columns>
                </asp:GridView>
            </asp:View>


            <asp:View ID="View_2" runat="server">                

                <h4>All Courses Of selected Prof</h4>

                <asp:GridView runat="server" ID="GridView_2"
                    AutoGenerateColumns="False"
                    AllowPaging="true"
                    OnPageIndexChanging="GridView_2_PageIndexChanging">
                    <Columns>
                        <asp:BoundField DataField="id_course" HeaderText="ID" />
                        <asp:BoundField DataField="name_course" HeaderText="Course Name" />
                        <asp:BoundField DataField="description" HeaderText="Description" />
                    </Columns>
                </asp:GridView>

                <asp:Button ID="ReturnButton" Text="Go back to List" runat="server" OnClick="ReturnButton_Click" />
            </asp:View>
        </asp:MultiView>

代码背后:

public partial class Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public IQueryable<DTO> GridView_1_GetData()
    {
        ModelData db = new ModelData();

        var result = ..... a complex Linq query .....

        return result.OrderByDescending(c => c.Count);

    }


    protected void GridView_1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = GridView_1.Rows[index];
            int idProf = Convert.ToInt32(row.Cells[0].Text);
            Details_Courses(idProf); /*** Call to Details_Courses function  ***/
            MultiView.ActiveViewIndex = 1;
        }
    }

    private void Details_Courses(int id)
    {
        ModelData db = new ModelData();

        var query = (from c in db.Courses                         
                     where c.id_prof == id
                     select new { c.id_course, c.name_course, c.description }).ToList();

        GridView_2.DataSource = query;
        GridView_2.DataBind();
    }

    protected void GridView_2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView_2.PageIndex = e.NewPageIndex;
        GridView_2.DataBind();
    }

    protected void ReturnButton_Click(object sender, EventArgs e)
    {
        MultiView.ActiveViewIndex = 0;
    }
}

注意:这只是一个例子 - 教授&amp;课程 。但我有另一个数据库

0 个答案:

没有答案