根据我的下拉列表中选择的字符串加载gridView [英] load gridView according to selected string in my dropdownlist

查看:71
本文介绍了根据我的下拉列表中选择的字符串加载gridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试根据我的下拉列表中选择的字符串加载gridView.Check下面的代码.但是奇怪的是,它给了我一个错误,说:

Hi

Am trying to load gridView according to selected string in my dropdownlist.Check the code below. But weird thing, it gives me an error that says:

A field or property with the name 'name' was not found on the selected data source.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the name 'name' was not found on the selected data source.

Source Error:


Line 121:            grdAvailableStuff.DataSource = dt;
Line 122:
Line 123:            grdAvailableStuff.DataBind();
Line 124:        }
Line 125:




而且我的数据源中没有该名称,但现在已经丢失了,我应该寻找这个名称吗?



下面是存储过程:




And I dont have that name in my data source and now am lost, wher should i look for this?



Below is the Stored procedure:

ALTER PROCEDURE [dbo].[procGetSelectedStaffMemberAvailableTimeSlot]
@Date nVarChar(20),@EmpRecNum nVarChar(50)
AS

SELECT   Employee.EmpName+' '+Employee.EmpSurname AS FullName,  AppointmentSlots.AvailabilityTimes, Employee.EmpRecNumber
FROM         AppointmentSlots INNER JOIN
                      Employee ON AppointmentSlots.EmpRecNumber = Employee.EmpRecNumber
WHERE     Employee.EmpRecNumber=@EmpRecNum AND AppointmentSlots.Date=@Date


================================================== =============

我班上的代码
================================================== =============


================================================================

Code from My Class
================================================================

public DataTable grdLoadSpecificEmployee(string date, string id)
        {
            using (SqlConnection con = new SqlConnection(ConnString))
            {
                SqlCommand cmd = new SqlCommand("procGetSelectedStaffMemberAvailableTimeSlot", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Date", SqlDbType.NVarChar));
                cmd.Parameters["@Date"].Value = date;
                cmd.Parameters.Add(new SqlParameter("@EmpRecNum", SqlDbType.NVarChar));
                cmd.Parameters["@EmpRecNum"].Value = id;
                DataTable dTable = new DataTable("dTable");
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(dTable);
                return dTable;

            }

        }


================================================== ============


下拉列表后面的代码
================================================== =============


===============================================================


Code behind the dropdownlist
================================================================

protected void ddlStaff_SelectedIndexChanged(object sender, EventArgs e)
  {
      string var = ddlStaff.SelectedValue.ToString();
      if (ddlStaff.SelectedValue == var)
      {
          MessageBox.Show(var.ToString());

          DataTable dt = new DataTable();
          systemBusinessLayer = new BusinessLayer();

          dt = systemBusinessLayer.grdLoadSpecificEmployee(DatePicker.SelectedDate.ToShortDateString(), var);
          grdAvailableStuff.DataSource = dt;

          grdAvailableStuff.DataBind();
      }




  }


================================================== ============


以下是加载dropdownlis的代码

来自Businesslayer的代码
================================================== ============


===============================================================


Below is the code for loading the dropdownlis

Code from Businesslayer
===============================================================

public ArrayList ddlAvailableStaffPerDay(string date)
       {
           using (SqlConnection con = new SqlConnection(ConnString))
           {
               SqlCommand cmd = new SqlCommand("procGetEmployeesForSpecificDay", con);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@Date", SqlDbType.NVarChar));
               cmd.Parameters["@Date"].Value = date;
               ArrayList myList = new ArrayList();
               try
               {
                   con.Open();
                   SqlDataReader read = cmd.ExecuteReader();
                   while (read.Read())
                   {
                       ClsEmployees employees = new ClsEmployees(Convert.ToInt32(read["EmpRecNumber"]), Convert.ToString(read["EmpName"]), Convert.ToString(read["EmpName"]));
                       myList.Add(employees);
                   }
                   read.Close();
               }
               catch (Exception exp)
               {
                   throw new ApplicationException(exp.Message);
               }
               return myList;
           }
       }


================================================== ==========

以下是我如何加载下拉菜单
================================================== ==========


============================================================

Below is how i load the dropdown
============================================================

public void populateDDLStaff()
    {
        ArrayList staffList = new ArrayList();
        systemBusinessLayer = new BusinessLayer();
        staffList = systemBusinessLayer.ddlAvailableStaffPerDay(DatePicker.SelectedDate.ToShortDateString());
     
        ddlStaff.DataSource = staffList;
        ddlStaff.DataTextField = "EmployeeName1";
        ddlStaff.DataValueField = "EmpRecNumber1";
        ddlStaff.DataBind();   
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        
        populateDDLStaff();
       
        DataTable dt = new DataTable();
        systemBusinessLayer = new BusinessLayer();
        dt = systemBusinessLayer.grid(DatePicker.SelectedDate.ToShortDateString());
        grdAvailableStuff.DataSource = dt;
        grdAvailableStuff.DataBind();   
    }



希望这是足够的信息



Hope this is enough information

推荐答案

似乎,根据您的异常消息,数据源列名称和网格视图列名称不匹配.因此,请确保您的数据源字段名称和Gridview字段名称应该匹配.

谢谢
It''s seems, Datasource column name and grid view column name is being mismatch as per you Exception message. So make sure your data source field name and Gridview field name should be match.

Thanks


这篇关于根据我的下拉列表中选择的字符串加载gridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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