页面里有个dropdownlist(ddl),objectdatasource(ods)会根据ddl的选项自动根据函数GetProgramByCID 更新数据库,并绑定到GridVIew里,现在问题是传参问题,ods设置的select的参数是ddl里的chlid,但是ods做更新删除时都是用的Program类型,一执行更新操作就提示ods找不到制定的属性,是不是ods的参数设置问题啊?因为调试的时候,还没执行方法就报错了。。我是小白,求各位高手帮忙未能在 ObjectDataSource“ObjectDataSource2”中的 DataObjectTypeName 属性指定的类型中找到名为“ChannelId”的属性。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 未能在 ObjectDataSource“ObjectDataSource2”中的 DataObjectTypeName 属性指定的类型中找到名为“ChannelId”的属性。
前台的<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ProgramManage.aspx.cs" Inherits="Admin_ProgramManage" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table class="style8" cellpadding="0" cellspacing="0">
<tr>
<td>
<table align="right">
<tr>
<td align="left" style=" width:60px">
<asp:Label ID="Label1" runat="server" Text="频道:"></asp:Label>
</td>
<td align="left" style=" width:250px" >
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="ObjectDataSource1" DataTextField="Name" DataValueField="Id"
Width="200px" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="Channel"
SelectMethod="ShowAllChannel" TypeName="ChannelClass">
</asp:ObjectDataSource>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td style=" height:350px; width:600px" valign="top">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
DataKeyNames="Id"
DataSourceID="ObjectDataSource2" onprerender="GridView1_PreRender"
onrowcreated="GridView1_RowCreated" PageSize="8"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
DeleteText="<div id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除</div> " />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" DataObjectTypeName="Program" UpdateMethod="UpdateProgram"
SelectMethod="GetProgramByCID" TypeName="ProgramClass">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="chlid"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Content>后台方法public DataTable GetProgramByCID(int chlid)
{
Program prm = new Program();
prm.Cid = chlid;
GetClass gcobject = new GetClass();
DataTable dt = new DataTable();
dt = gcobject.DB_GetProgramByCID(prm);
return dt;
}
[DataObjectMethod(DataObjectMethodType.Update)]
public bool UpdateProgram(int pid,string name,bool enab,int chlid)
{
Program prm = new Program();
prm.Pid = pid;
prm.Name = name;
prm.Enabled = enab;
prm.Cid = chlid;
UpdateClass ucobject = new UpdateClass();
int re = ucobject.DB_UpdateProgram(prm);
if (re != 100)
return false;
else
return true;
}
Program类
public class Program
{
public Program()
{
//
//TODO: 在此处添加构造函数逻辑
//
} protected int _programID;
protected string _programName;
protected bool _programEnable;
protected int _channelID; public int Pid
{
get { return _programID; }
set { _programID = value; }
} public string Name
{
get { return _programName; }
set { _programName = value; }
} public bool Enabled
{
get { return _programEnable; }
set { _programEnable = value; }
} public int Cid
{
get { return _channelID; }
set { _channelID = value; }
} public Program(int programID, string programName, bool programEnable, int channelID)
{
this._programID = programID;
this._programName = programName;
this._programEnable = programEnable;
this._channelID = channelID;
}
}
public int DB_UpdateProgram(Program prm)
{
SqlCommand myCmd = dbobject.GetCommandProc("Proc_UpdateProgram");
SqlParameter MProgramId = new SqlParameter("@ProgramId", SqlDbType.Int, 4);
SqlParameter MProgramName = new SqlParameter("@Name", SqlDbType.NVarChar, 100);
SqlParameter MProgramEnable = new SqlParameter("@Enabled", SqlDbType.Bit);
SqlParameter MProgramCID = new SqlParameter("@ChannelId", SqlDbType.Int, 4);
MProgramId.Value = prm.Pid;
MProgramName.Value = prm.Name;
MProgramEnable.Value = prm.Enabled;
MProgramCID.Value = prm.Cid; myCmd.Parameters.Add(MProgramId);
myCmd.Parameters.Add(MProgramName);
myCmd.Parameters.Add(MProgramEnable);
myCmd.Parameters.Add(MProgramCID); SqlParameter ReturnValue = myCmd.Parameters.Add("ReturnValue", SqlDbType.Int, 4);
ReturnValue.Direction = ParameterDirection.ReturnValue;
dbobject.ExecNonQuery(myCmd); return Convert.ToInt32(ReturnValue.Value.ToString());
}
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 未能在 ObjectDataSource“ObjectDataSource2”中的 DataObjectTypeName 属性指定的类型中找到名为“ChannelId”的属性。
前台的<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ProgramManage.aspx.cs" Inherits="Admin_ProgramManage" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table class="style8" cellpadding="0" cellspacing="0">
<tr>
<td>
<table align="right">
<tr>
<td align="left" style=" width:60px">
<asp:Label ID="Label1" runat="server" Text="频道:"></asp:Label>
</td>
<td align="left" style=" width:250px" >
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="ObjectDataSource1" DataTextField="Name" DataValueField="Id"
Width="200px" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="Channel"
SelectMethod="ShowAllChannel" TypeName="ChannelClass">
</asp:ObjectDataSource>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td style=" height:350px; width:600px" valign="top">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
DataKeyNames="Id"
DataSourceID="ObjectDataSource2" onprerender="GridView1_PreRender"
onrowcreated="GridView1_RowCreated" PageSize="8"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
DeleteText="<div id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除</div> " />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" DataObjectTypeName="Program" UpdateMethod="UpdateProgram"
SelectMethod="GetProgramByCID" TypeName="ProgramClass">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="chlid"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Content>后台方法public DataTable GetProgramByCID(int chlid)
{
Program prm = new Program();
prm.Cid = chlid;
GetClass gcobject = new GetClass();
DataTable dt = new DataTable();
dt = gcobject.DB_GetProgramByCID(prm);
return dt;
}
[DataObjectMethod(DataObjectMethodType.Update)]
public bool UpdateProgram(int pid,string name,bool enab,int chlid)
{
Program prm = new Program();
prm.Pid = pid;
prm.Name = name;
prm.Enabled = enab;
prm.Cid = chlid;
UpdateClass ucobject = new UpdateClass();
int re = ucobject.DB_UpdateProgram(prm);
if (re != 100)
return false;
else
return true;
}
Program类
public class Program
{
public Program()
{
//
//TODO: 在此处添加构造函数逻辑
//
} protected int _programID;
protected string _programName;
protected bool _programEnable;
protected int _channelID; public int Pid
{
get { return _programID; }
set { _programID = value; }
} public string Name
{
get { return _programName; }
set { _programName = value; }
} public bool Enabled
{
get { return _programEnable; }
set { _programEnable = value; }
} public int Cid
{
get { return _channelID; }
set { _channelID = value; }
} public Program(int programID, string programName, bool programEnable, int channelID)
{
this._programID = programID;
this._programName = programName;
this._programEnable = programEnable;
this._channelID = channelID;
}
}
public int DB_UpdateProgram(Program prm)
{
SqlCommand myCmd = dbobject.GetCommandProc("Proc_UpdateProgram");
SqlParameter MProgramId = new SqlParameter("@ProgramId", SqlDbType.Int, 4);
SqlParameter MProgramName = new SqlParameter("@Name", SqlDbType.NVarChar, 100);
SqlParameter MProgramEnable = new SqlParameter("@Enabled", SqlDbType.Bit);
SqlParameter MProgramCID = new SqlParameter("@ChannelId", SqlDbType.Int, 4);
MProgramId.Value = prm.Pid;
MProgramName.Value = prm.Name;
MProgramEnable.Value = prm.Enabled;
MProgramCID.Value = prm.Cid; myCmd.Parameters.Add(MProgramId);
myCmd.Parameters.Add(MProgramName);
myCmd.Parameters.Add(MProgramEnable);
myCmd.Parameters.Add(MProgramCID); SqlParameter ReturnValue = myCmd.Parameters.Add("ReturnValue", SqlDbType.Int, 4);
ReturnValue.Direction = ParameterDirection.ReturnValue;
dbobject.ExecNonQuery(myCmd); return Convert.ToInt32(ReturnValue.Value.ToString());
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货