GridView绑定问题

时间:2011-07-14 06:01:22

标签: c# asp.net gridview

我的网格遇到了一个奇怪的问题。我的aspx页面中有一个网格和一个DDL程序。我的目标是将网格与整个列表绑定(不进行过滤)。我实现了这个目标。我的第二个目标是从DDL中选择一个程序,然后根据选择过滤列表。我也得到了这个过滤器列表。但是当我尝试绑定此列表时,数据绑定仍然不成功。它没有显示任何错误。我调试了它但发现没有任何线索出错。我的代码是

protected void Page_Load(object sender, EventArgs e) 
{
    if (!IsPostBack) 
    {
        Bind_Grid();
        Bind_Program();
    }
}

private void Bind_Program() 
{
    List < CcProgramEntity > programEntities = FormSaleSubmit_BAO.GetAllPrograms();

    if (programEntities == null) 
    {
        //lblErrorMessage.Visible = true;
        //lblErrorMessage.Text = "No Program Found";
        return;
    }

    DDLProgram.DataSource = programEntities;
    DDLProgram.DataTextField = "Shortname";
    DDLProgram.DataValueField = "Id";
    DDLProgram.DataBind();
    //throw new NotImplementedException();
}

private void Bind_Grid() 
{
    List < FormGridEntity > formGridEntities = new List < FormGridEntity > ();
    if (DDLProgram.SelectedIndex >= 0) 
    {
        string shortName = DDLProgram.SelectedItem.ToString();

        formGridEntities = FormSaleSubmit_BAO.GetAllCandidateInfoByProgram(shortName);

    } else 
    {
        formGridEntities = FormSaleSubmit_BAO.GetAllCandidateInformation();
    }

    gridViewFormSaleSubmit.DataSource = null;
    gridViewFormSaleSubmit.DataBind();
    if (formGridEntities != null) 
    {
        gridViewFormSaleSubmit.DataSource = formGridEntities;
        gridViewFormSaleSubmit.DataBind();
    } else 
    {
        //what to do
        Variables.SaveMode = SaveMode.Add;
        Response.Redirect("FormSaleSubmissionInfo.aspx");
    }
}

protected void OnDDLProgramChanged(object sender, EventArgs e) 
{
    List < CcProgramEntity > programEntities = FormSaleSubmit_BAO.GetAllPrograms();
    if (programEntities == null) 
    {
        //lblErrorMessage.Text = "Could not find any program!";
        return;
    }
    Bind_Grid();
}

0 个答案:

没有答案