无法将类型为“personnelModel.RS_HolidayType”的对象强制转换为类型“System.Data.DataRowView”。

lihui123 2009-08-18 02:22:24
protected void AdjustType_gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton TempIB_Del = (ImageButton)e.Row.FindControl("lb_del");
TempIB_Del.CommandName = "Person_del";
TempIB_Del.CommandArgument = e.Row.RowIndex.ToString();
TempIB_Del.Attributes.Add("onclick", "return confirm('真的删除吗?');");

ImageButton TempIB_Mod = (ImageButton)e.Row.FindControl("lb_mod");
TempIB_Mod.CommandName = "Adjust_Mod";
TempIB_Mod.CommandArgument = e.Row.RowIndex.ToString();
TempIB_Mod.Attributes.Add("onclick", "return confirm('真的修改吗?')");



TextBox tempTr = (TextBox)e.Row.Cells[1].FindControl("F_Time");
DataRowView tempDr = (DataRowView)e.Row.DataItem;
tempTr.Text = tempDr.Row["H_HolidayTime"].ToString();无法将类型为“personnelModel.RS_HolidayType”的对象强制转换为类型“System.Data.DataRowView”。
TextBox tempTB = (TextBox)e.Row.Cells[1].FindControl("AT_Name");
DataRowView tempDv = (DataRowView)e.Row.DataItem;
tempTB.Text = tempDv.Row["H_Bank"].ToString();

TextBox tempTa = (TextBox)e.Row.Cells[1].FindControl("S_Address");
DataRowView tempDa = (DataRowView)e.Row.DataItem;
tempTa.Text = tempDa.Row["H_HolidayType"].ToString();
}
if (e.Row.RowType == DataControlRowType.Pager)
{
Label Templb = (Label)e.Row.FindControl("Recordcount_lb");
Templb.Text = _HolidaySet.RecordCount;
Templb = (Label)e.Row.FindControl("Pagecount_lb");
Templb.Text = AdjustType_gv.PageCount.ToString();
Templb = (Label)e.Row.FindControl("abbPage_lb");
Templb.Text = Convert.ToString(AdjustType_gv.PageIndex + 1);
}
}





protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
RS_Person_BLL rpb = new RS_Person_BLL();
List<RS_HolidayType> list = rpb.SearchHolidayType(txtHolidayTime.Text);
if (list.Count > 0)
{
AdjustType_gv.DataSource = list;
AdjustType_gv.DataBind();
}
else
{
Tongyong.ShowError(ChkMessage_Panel, ChkMessage_lb, "你输入的搜索条件不正确!");

AdjustType_gv.Visible = false;

ChkMessage_Cancel_Click(sender, e);
}
}
catch (Exception ex) 捕获:无法将类型为“personnelModel.RS_HolidayType”的对象强制转换为类型“System.Data.DataRowView”。 {

Tongyong.ShowError(ChkMessage_Panel, ChkMessage_lb, "你输入的搜索条件不正确!");
}
}
...全文
136 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihui123 2009-08-19
  • 打赏
  • 举报
回复
方法 是List <RS_HolidayType> list ………… 这个 ,


GridView 有模板列 想把 list 作为数据源
Jinglecat 2009-08-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lihui123 的回复:]
幕白兄……帮帮忙啊 ! 我 GridView  有几列用的是模板列,    后台的  搜索方法是  绑定在Gridview上的数据源是  List <RS_HolidayType> list …………实体
[/Quote]


数据源是 RS_HolidayType 还用 DataView ?

DataRowView tempDr = (DataRowView)e.Row.DataItem;
RS_HolidayType tempH = (RS_HolidayType)e.Row.DataItem;
tempTr.Text = tempDr.Row["H_HolidayTime"].ToString();无法将类型为“personnelModel.RS_HolidayType”的对象强制转换为类型“System.Data.DataRowView”。
tempTr.Text = tempH.你的属性名
Lovely_baby 2009-08-19
  • 打赏
  • 举报
回复
tempTr.Text = (DataRowView)tempDr.Row["H_HolidayTime"].ToString();
lihui123 2009-08-19
  • 打赏
  • 举报
回复
幕白兄……帮帮忙啊 ! 我 GridView 有几列用的是模板列, 后台的 搜索方法是 绑定在Gridview上的数据源是 List <RS_HolidayType> list …………实体
lihui123 2009-08-19
  • 打赏
  • 举报
回复
好几天没解决了 幕白兄………… 帮帮忙啊 !

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧