修复数据绑定:"System.Data.DataRowView"不包含名称为“ [英] Fix- DataBinding: 'System.Data.DataRowView' does not contain a property with the name
问题描述
创建 过程 St_Proc_GetUserReportforCurrentDayTask
@ userID int
为
开始
set NoCount on ;
声明 @ TODAY DATE
设置 @ TODAY = 转换( VARCHAR ( 10 ),GETDATE(), 111 )
选择 转换( VARCHAR ,生产.CalendarDate , 101 )+ RIGHT (>转换( VARCHAR ,production.CalendarDate, 100 ), 7 )原为 日期,
RegionAndProjectInfo.RegionProjectName 作为地区,
County.CountyName as 县,
WorkType.WorkTypeName as WorkType,
Task.TaskName 作为任务,
Production.VolumeProcessed 作为 ' 已处理的体积' ,
Production.TimeSpent as ' Duration(HH:MM)'
来自生产
内部 加入 RegionAndProjectInfo
上
RegionAndProjectInfo.RegionProjectID =生产.RegionProjectID
内部 加入县
上
County.CountyID =生产.县ID
内部 加入 WorkType
上
WorkType.WorkTypeID = Production.WorkTypeID
内部 加入任务
上
Task.TaskID =生产.任务ID
其中 Production.UserID=@userID and CalendarDate> = @TODAY
结束
这是我的存储过程,我正在执行此存储过程,并将结果保存在数据集中,然后将网格与此数据集绑定. ="c#"> 私有 void BindGridOnPageLoad()
{
_production = 新 EmployeeQuotientCL.Production();
_userEcode = Convert.ToString(会话[" ]);
int _userID = _production.GetUserIDFromDB(_userEcode);
dsUserTaskDetails = _production.GetTabularUsertaskDetails(_userID);
BindGridView(dsUserTaskDetails);
} 但是,当我调试时遇到此错误:-"DataBinding:" System.Data.DataRowView"不包含名称为"Duration"的属性."我在做什么错误,以及如何解决?
到这里为止一切都很好.然后我要求在网格视图的页脚中显示总计Duration(HH:MM).我在页面中添加了以下代码:- < div =" gridview" > ;
< asp:GridView ID =" runat 服务器" ShowFooter true" CssClass mGrid" CellSpacing =" onselectedindexchanged =" onrowdatabound =" GridView1_RowDataBound" < /asp:GridView >
受保护的 void GridView1_RowDataBound(如果(例如,Row.RowType == DataControlRowType.DataRow)
{
tp + = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem," ));
}
如果(例如,Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells [ 0 ].Text = " ;
e.Row.Cells [ 1 ].Text = tp.ToString(" );
e.Row.Cells [ 0 ].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells [ 1 ].HorizontalAlign = HorizontalAlign.Right;
e.Row.Font.Bold = true ;
}
}
是的,您在gridview的RowDataBound事件中的代码正在尝试查找"Duration"行,该行不存在在您的网格视图中.试试这个:
tp + = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem," ));
祝一切顺利.
--Amit
Dharmendra,
问题出在代码的这一行:
"tp + = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem," Duration(HH:MM))));"
对此进行更正或指定您要在此时进行的操作,以便我们在需要时可以为您提供进一步的帮助.
希望有帮助!
快乐编码:)
create procedure St_Proc_GetUserReportforCurrentDayTask
@userID int
as
Begin
set NoCount on;
DECLARE @TODAY DATE
SET @TODAY = CONVERT(VARCHAR(10), GETDATE(), 111)
select CONVERT(VARCHAR,production.CalendarDate,101) + RIGHT (CONVERT(VARCHAR,production.CalendarDate , 100 ) ,7) as Date,
RegionAndProjectInfo.RegionProjectName as Region ,
County.CountyName as County,
WorkType.WorkTypeName as WorkType,
Task.TaskName as Task,
Production.VolumeProcessed as 'Volumes Processed',
Production.TimeSpent as 'Duration(HH:MM)'
from Production
inner join RegionAndProjectInfo
on
RegionAndProjectInfo.RegionProjectID=Production.RegionProjectID
inner join County
on
County.CountyID=Production.CountyID
inner join WorkType
on
WorkType.WorkTypeID=Production.WorkTypeID
inner join Task
on
Task.TaskID=Production.TaskID
where Production.UserID=@userID and CalendarDate >= @TODAY
End
This is my stored procedure and i am executing this stored procedure and saving the result in a dataset and then binding a grid with this dataset.
private void BindGridOnPageLoad()
{
_production = new EmployeeQuotientCL.Production();
_userEcode = Convert.ToString(Session["UserID"]);
int _userID = _production.GetUserIDFromDB(_userEcode);
dsUserTaskDetails = _production.GetTabularUsertaskDetails(_userID);
BindGridView(dsUserTaskDetails);
}
Up to here every thing is fine .Then i got requirement to show Duration(HH:MM) total in the footer of the grid view.I had added following code in the page:-
<div id="gridview">
<asp:GridView ID="GVUserEnteredDetails" runat="server" ShowFooter="true" CssClass="mGrid" CellSpacing="2" onselectedindexchanged="GVUserEnteredDetails_SelectedIndexChanged" onrowdatabound="GridView1_RowDataBound">
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
tp += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Duration(HH:MM)"));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "Total Hours : ";
e.Row.Cells[1].Text = tp.ToString("c");
e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
e.Row.Font.Bold = true;
}
}
But when i am debugging i m getting this error:- "DataBinding: ''System.Data.DataRowView'' does not contain a property with the name ''Duration''." What the mistake i m doing and how to fix it? Any suggestion and help will be helpful for me.
Yes, your code in RowDataBound event of gridview is trying to find the row "Duration", which is not there in your gridview. Try this:
tp += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "[Duration(HH:MM)]"));
All the best.
--Amit
Hi Dharmendra,
The problem lies in this line of your code:
" tp += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Duration(HH:MM)"));"
rectify this one or specify what you''re trying to do at this point, so that we can assist you further if it needs.
Hope this help!
Happy Coding :)
这篇关于修复数据绑定:"System.Data.DataRowView"不包含名称为“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!