Click here to Skip to main content
15,895,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm Working in grid-view.
I have to Bind data from list to grid-view i have tried it , but it is getting Exception that "A field or property with the name 'UM_Employee_Number' was not found on the selected data source" could you please help me on this

.CS
protected void btnSrchBox_Click(object sender, EventArgs e)
{
string srchEmpID = txtSrchEmpID.Text;
string srchEmpName = txtSrchEmpName.Text;
// Users UserControllerObjct = new Users();
//List<users> UserControllerObjct = new List<users>();
var lstSrchEmp = new List<user>();
//lstSrchEmp = UserControllerObjct.SearchEmployeeDetails();
TCSRR.DMTController.Users UserControllerObjct = new TCSRR.DMTController.Users();
// TCSRR.DMTBusinessEntity.User lstSrchEntityObj = new TCSRR.DMTBusinessEntity.User();
lstSrchEmp = UserControllerObjct.SearchEmployeeDetails(srchEmpID, srchEmpName);
if (lstSrchEmp.Count > 0)
{

gridView1.DataSource = lstSrchEmp;
// gridView1.DataSource = UserControllerObjct.SearchEmployeeDetails(srchEmpID, srchEmpName);
gridView1.DataBind();
}



}


Controller

public List<user> SearchEmployeeDetails(string srchEmpID, string srchEmpName)
{
UserData UserModelObj = new UserData();
List<user> UserEntityObj = new List<user>();

// TCSRR.DMTModel.Users UserControllerObjct = new TCSRR.DMTController.Users();
// TCSRR.DMTBusinessEntity.User lstSrchEntityObj = new TCSRR.DMTBusinessEntity.User();
// UserData srchusers = new UserData();
// List<user> SrchLstUser = new List<user>();
// TCSRR.DMTBusinessEntity.User SrchLstUser = new TCSRR.DMTBusinessEntity.User();
try
{
UserEntityObj = UserModelObj.SearchEmployeeDetails(srchEmpID, srchEmpName);
//return (srchusers.SearchEmployeeDetails(srchEmpID, srchEmpName));
return UserEntityObj;
}
catch (Exception ex)
{
//SrchLstUser.Add(new User());
ex.CustomException("1", "User Details can't be retrived");
}
return null;
}
}


Model

public List<user> SearchEmployeeDetails(string srchEmpID, string srchEmpName)
{
DataSet ds;
User SrchUser;
List<user> SrchLst = new List<user>();

//TCSRR.DMTBusinessEntity.User SrchLst =new TCSRR.DMTBusinessEntity.User();

try
{
object[] arParms = new object[2];
arParms[0] = srchEmpID;
arParms[1] = srchEmpName;
ds = SqlHelper.ExecuteDataset(FileManager.GetSettingsValue("DBConnection"), "spmt_SearchEmployee", arParms);
if (ds != null)
{
// return ds;
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
SrchUser = new User();
SrchUser.EmployeeNo = ds.Tables[0].Rows[0]["UM_Employee_Number"].ToString();
SrchUser.FirstName = ds.Tables[0].Rows[i]["UM_FirstName"].ToString();

SrchLst.Add(SrchUser);
return SrchLst;
}
}
}
}
catch (Exception ex)
{

}
return null;

}
}


Please it is urgen
Posted

I think spmt_SearchEmployee is not returning the UM_Employee_Number field in the dataset that is why u r getting that exception
 
Share this answer
 
Comments
sushma_bhardwaj 12-Mar-14 1:07am    
ALTER PROCEDURE [dbo].[spmt_SearchEmployee]
@UM_Employee_Number nvarchar(15),
@UM_FirstName nvarchar(30)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT UM_Employee_Number , UM_FirstName
FROM User_Master
WHERE UM_Employee_Number= @UM_Employee_Number OR UM_FirstName= @UM_FirstName;

--WHERE UM_Employee_Number CONTAINS(@UM_Employee_Number) ;
END



here is my Storeprocedure
sushma_bhardwaj 12-Mar-14 1:08am    
When i trace this loop.. it is taking data from Db wen it comes gridView1.DataBind(); it is showing exception "A field or property with the name 'UM_Employee_Number' was not found on the selected data source"
I think you are not binding correct field in the gridview present in aspx. Check the DataField corresponding to the asp:BoundField tag in the gridview code
 
Share this answer
 
Comments
sushma_bhardwaj 14-Mar-14 4:57am    
<asp:GridView ID="gridView1" runat="server" AutoGenerateColumns="false" Height="72px"
Visible="true" Width="152px" onselectedindexchanged="gridView1_SelectedIndexChanged"
>
<%--onselectedindexchanged="gridView1_SelectedIndexChanged1"--%>
<%--OnDataBound="gridView1_SelectedIndexChanged"--%>
<%--OnDataBound="btnSrchAgign"--%> <%-- OnDataBound="srchEmp_DataBound" --%>
<columns>
<asp:BoundField DataField="UM_Employee_Number" HeaderText="ID"
sortExpression="UM_Employee_Number" />
<asp:BoundField DataField="UM_FirstName" HeaderText="Name"
sortExpression="UM_FirstName" />
<asp:TemplateField Visible="False">
<itemtemplate>
<asp:LinkButton ID="SrchLinkSelect" runat="server" CommandName="select"
Text="Select" />

<HeaderStyle BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
VerticalAlign="Middle" />
<itemstyle borderstyle="Solid" borderwidth="1px" horizontalalign="Left"
="" verticalalign="Middle" wrap="False">

<asp:TemplateField HeaderText="Select">
<itemtemplate>
<asp:ImageButton ID="imgBtnSrchSelect" runat="server" Height="18px"
ImageAlign="Middle" ImageUrl="~/Images/grid_edit.png" Width="22px" />
<%--OnClick="btnSrchAgign"--%>



sushma_bhardwaj 14-Mar-14 4:57am    
I have created aspx page as above.. could you pls verify that ..
sushma_bhardwaj 14-Mar-14 5:39am    
It is very urget for me.
it ll be very helpfull . somone can get the solution for this.
sushma_bhardwaj 14-Mar-14 9:33am    
@gagandeep.pratihar680 :
If i eturn the dataset , the binding is coming properly,
if i return through list , Exception is coming.. pls pls pls .. could u pls help me on this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900