在下拉列表选择中显示gridview中的行数 [英] display the number of rows in a gridview on dropdownlist selection

查看:114
本文介绍了在下拉列表选择中显示gridview中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,早上好,
我正在尝试在下拉列表选择上的gridview中显示行数.但是问题i
面临的问题是,页面加载第一次显示相关结果,但是从DDL Grid视图中选择其他一些值时就不会进行迭代.
请帮我这个.. ??
这是代码:
在.aspx中,我采取了1个DDL和1个网格视图
在代码行为中:

hello GoodMorning,
i am trying to display the number of rows in a gridview on dropdownlist selection.But the problem i
am facing is that on page load for the first time its showing relevent result but on selecting some other value from the DDL Grid view is not iterating.
Please help me with this..??
here is the code:
in .aspx i have taken 1 DDL and 1 Grid view
in code behing:

public partial class GridViewDemo : System.Web.UI.Page
{
    private void BindGridView1()
    {
        try
        {
            this.GridView1.DataSource = ProjectManager.GetHoodListing();
            this.GridView1.DataBind();
        }
        catch (Exception ex)
        { throw ex; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                BindGridView1();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView1.PageSize = Convert.ToInt32(DropDownList1.SelectedValue);
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

            }
        }
        catch (Exception ex)
        { throw ex; }
    }
**************************************************
// project manager class

 public static DataTable GetHoodListing()
    {
        DataAccess objDA = new DataAccess();
        DataTable objDT = new DataTable();
        string strSql = "";
        try
        {
            strSql = string.Format("SELECT HLID, HLSeries, HLStyle, HLCanopProfile FROM HoodListing");
            objDT = objDA.ExecuteDataTable(strSql);
        }
        catch (SqlException sqlex)
        { throw sqlex; }
        catch (Exception ex)
        { throw ex; }

        return objDT;
    }

推荐答案

GridView1_PageIndexChanging 事件中包含 BindGridView1(); .
您将得到它.
include BindGridView1(); in GridView1_PageIndexChanging event.
u will get it.


您忘记了在PageIndexChanging事件中重新定义DataSource.

将您的代码修改为:
You forgot to redefine DataSource in your PageIndexChanging event.

Modify your code to:
// Pagesize set at the time of binding
private void BindGridView1()
{
        try
        {
            this.GridView1.DataSource = ProjectManager.GetHoodListing();
            this.GridView1.DataBind();

            if(Convert.ToInt32(DropDownList1.SelectedValue) != null)
              GridView1.PageSize = Convert.ToInt32(DropDownList1.SelectedValue);
        }
        catch (Exception ex)
        { throw ex; }
}

// page changed and grid rebind to reflect change
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
        GridView1.PageIndex = e.NewPageIndex;
        BindGridView1();
}

//To set grid with defined page as per set
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
       BindGridView1();
}


这篇关于在下拉列表选择中显示gridview中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆