从vb改成c#的语句提示错误。
在vb.net:
DataSource='<%# FilterProducts( Container.DataItem( "CategoryID" ) )%>'
为什么,在C#这样写:
DataSource='<%# FilterProducts(DataBinder.Eval(Container.DataItem,"CategoryID"))%>'
就提示错误
问题点数:20、回复次数:15Top
1 楼hiweiyi2000(胖子)回复于 2005-07-20 09:27:17 得分 0
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS1502: 与“ASP.NestedRowFilter_aspx.FilterProducts(int)”最匹配的重载方法具有一些无效参数
源错误:
行 43: <ItemTemplate>
行 44: <h2><%#DataBinder.Eval(Container.DataItem, "CategoryName" )%></h2>
行 45: <asp:DataGrid
行 46: DataSource='<%#FilterProducts(DataBinder.Eval(Container.DataItem, "CategoryID" )) %>'
行 47: Runat="Server" />
源文件: G:\note\s\NestedRowFilter.aspx 行: 45
Top
2 楼hdt(倦怠)回复于 2005-07-20 09:30:44 得分 10
public FilterProducts( string strid )
{
int nid = int.parse(strid);
.....
}Top
3 楼chengbo1983(chengbo.net)回复于 2005-07-20 09:35:19 得分 0
同上Top
4 楼hiweiyi2000(胖子)回复于 2005-07-20 09:45:04 得分 0
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat=server>
DataSet dstNorthwind;
DataView dvwProducts;
void Page_Load(Object sender , EventArgs e)
{
SqlConnection conNorthwind;
SqlDataAdapter dadNorthwind;
dstNorthwind = new DataSet();
conNorthwind = new SqlConnection( @"Server=localhost;UID=sa;PWD=weiYI10;Database=Northwind" );
dadNorthwind = new SqlDataAdapter( "Select * From Categories", conNorthwind );
dadNorthwind.Fill( dstNorthwind, "Categories" );
dadNorthwind.SelectCommand = new SqlCommand( "Select * From Products", conNorthwind );
dadNorthwind.Fill( dstNorthwind, "Products" );
dvwProducts = dstNorthwind.Tables[ "Products" ].DefaultView;
rptCategories.DataSource = dstNorthwind;
rptCategories.DataMember = "Categories";
rptCategories.DataBind();
}
DataView FilterProducts( int intCatID )
{
dvwProducts.RowFilter = "CategoryID=" + intCatID;
return dvwProducts;
}
</Script>
<html>
<head><title>NestedRowFilter.aspx</title></head>
<body>
<asp:Repeater
ID="rptCategories"
Runat="Server">
<ItemTemplate>
<h2><%#DataBinder.Eval(Container.DataItem, "CategoryName" )%></h2>
<asp:DataGrid
DataSource='<%#FilterProducts(DataBinder.Eval(Container.DataItem, "CategoryID" )) %>'
Runat="Server" />
</ItemTemplate>
</asp:Repeater>
</body>
</html>
我按上面的做了,但是没有解决问题。
将源码全上。Top
5 楼hdt(倦怠)回复于 2005-07-20 09:54:38 得分 10
DataView FilterProducts( string strId )
{
int intCatId = int.parse(strId);
dvwProducts.RowFilter = "CategoryID=" + intCatID;
return dvwProducts;
}
Top
6 楼hiweiyi2000(胖子)回复于 2005-07-20 10:01:05 得分 0
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS0117: “int”并不包含对“parse”的定义
源错误:
行 28: DataView FilterProducts( string strId )
行 29: {
行 30: int intCatId = int.parse(strId);
行 31: dvwProducts.RowFilter = "CategoryID=" + intCatID;
行 32: return dvwProducts;
源文件: G:\note\s\NestedRowFilter.aspx 行: 30
Top
7 楼hiweiyi2000(胖子)回复于 2005-07-20 10:01:27 得分 0
还没有解决。
错误提示如上。Top
8 楼jimu8130(火箭的未来在哪里?)回复于 2005-07-20 10:51:22 得分 0
如果你用convert。toint32()?Top
9 楼kongxing(我心飞翔)回复于 2005-07-20 10:59:14 得分 0
应该是C#中区分大小写的问题吧Top
10 楼hiweiyi2000(胖子)回复于 2005-07-20 11:47:35 得分 0
按照Convert.ToInt32
做了,不解决问题。
要求大家能实际动行调试过一次。
Top
11 楼hiweiyi2000(胖子)回复于 2005-07-20 17:36:22 得分 0
顶一下。
Top
12 楼webdiyer(.net资源精华—www.dotneturls.com)回复于 2005-07-20 17:59:41 得分 0
DataSource='<%# FilterProducts(int.Parse(DataBinder.Eval(Container.DataItem,"CategoryID")).ToString())%>'
这样也可以Top
13 楼hdt(倦怠)回复于 2005-07-21 05:17:15 得分 0
陕北的方法好
Top
14 楼hiweiyi2000(胖子)回复于 2005-07-21 11:06:28 得分 0
用了陕北的方法还是提示错误:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS1502: 与“int.Parse(string)”最匹配的重载方法具有一些无效参数
源错误:
行 43: <ItemTemplate>
行 44: <h2><%#DataBinder.Eval(Container.DataItem, "CategoryName" )%></h2>
行 45: <asp:DataGrid
行 46: DataSource='<%# FilterProducts(int.Parse(DataBinder.Eval(Container.DataItem,"CategoryID")).ToString())%>'
行 47:
Top
15 楼webdiyer(.net资源精华—www.dotneturls.com)回复于 2005-07-21 17:37:05 得分 0
Sorry,括号位置错了,应该是:
DataSource='<%# FilterProducts(int.Parse(DataBinder.Eval(Container.DataItem,"CategoryID").ToString()))%>Top




