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();
}
}
===============================================================
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