将列表数据显示到gridview中 [英] display list data into gridview
问题描述
我在网格视图中工作。
我必须将数据从列表绑定到网格视图我已经尝试过了,但它得到的异常是带有名称的字段或属性在所选数据源上找不到UM_Employee_Number你能帮我这个吗?
.CS
protected void btnSrchBox_Click(object发件人,EventArgs e)
{
string srchEmpID = txtSrchEmpID.Text;
string srchEmpName = txtSrchEmpName.Text;
//用户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() ;
}
}
控制器
公开列表< 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();
// List<使用者名称> SrchLstUser = new List< user>();
// TCSRR.DMTBusinessEntity.User SrchLstUser = new TCSRR.DMTBusinessEntity.User();
try
{
UserEntityObj = UserModelObj.SearchEmployeeDetails(srchEmpID,srchEmpName);
// return(srchusers.SearchEmployeeDetails(srchEmpID,srchEmpName));
返回UserEntityObj;
}
catch(例外情况)
{
//SrchLstUser.Add (新用户());
ex.CustomException(1,用户详细信息无法重试);
}
返回null;
}
}
型号
public List< user> SearchEmployeeDetails(string srchEmpID,string srchEmpName)
{
DataSet ds;
User SrchUser;
List< user> ; SrchLst =新列表< user>();
// TCSRR.DMTBusinessEntity.User SrchLst = new TCSRR.DMTBusinessEntity.User();
尝试
{
object [] arParms = new object [2];
arParms [0 ] = srchEmpID;
arParms [1] = srchEmpName;
ds = SqlHelper.ExecuteDataset(FileManager.GetSettingsValue(DBConnection),spmt_SearchEmployee,arParms);
if(ds!= null)
{
//返回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_Emp loyee_Number]。ToString();
SrchUser.FirstName = ds.Tables [0] .Rows [i] [UM_FirstName]。ToString();
SrchLst.Add(SrchUser);
返回SrchLst;
}
}
}
}
catch(例外情况)
{
}
返回null;
}
}
请紧急
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
推荐答案
我认为spmt_SearchEmployee没有返回数据集中的UM_Employee_Number字段,这就是为什么你得到的异常
I think spmt_SearchEmployee is not returning the UM_Employee_Number field in the dataset that is why u r getting that exception
我认为你没有在aspx中出现的gridview中绑定正确的字段。检查gridview代码中对应于asp:BoundField标记的DataField
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
这篇关于将列表数据显示到gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!