大侠帮忙啊!!!!写了一个自定义控件,继承自datagrid,编译的时候能通过!为什么把他拉到界面就出错呢??

ldw701 2005-01-14 04:07:45
编译的时候出错信息:
D:\WebSites\Test\TestVaildClient.aspx(12,31): error CS0433: The type 'SoftReg.UserDataGrid' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\Temporary ASP.NET Files\test\f0a45bd4\be3552d5\assembly\dl2\v2_d67516a7\00e33ad1_0efac401\UserDataGrid.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\Temporary ASP.NET Files\test\f0a45bd4\be3552d5\__codewdyus4_s.dll'
...全文
176 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Netmark 2005-01-17
  • 打赏
  • 举报
回复
我怎么感觉你这是写的派生自DataGrid的一个类

而不是一个组件

怎么没有override 重写
ldw701 2005-01-17
  • 打赏
  • 举报
回复
求救!!!!
ldw701 2005-01-14
  • 打赏
  • 举报
回复
private void UserDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if( this.SortDirection==" DESC")
{
this.SortDirection=" ASC";
}
else
{
this.SortDirection=" DESC";
}
this.SortField=e.SortExpression;
this.SortField=this.SortField.Replace("▲","");
this.SortField=this.SortField.Replace("▼","");
BindGrid();
}
private void UserDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
/*
try
{
string txt="";
for (int i = 0; i < 10;i++ )
{
// e.Item.Cells[i].Wrap=false;
txt = e.Item.Cells[i].Text.Trim();
if (myClass.IsDouble(txt))
{
e.Item.Cells[i].HorizontalAlign = HorizontalAlign.Right;
}
else
{
if (txt == arritem[i] && txt != "" && txt != null)
{
e.Item.Cells[i].Text = "";
}
else
{
arritem[i] = txt;
}
}
}
}
catch(Exception et)
{

}
*/
}
}
}
ldw701 2005-01-14
  • 打赏
  • 举报
回复
代码如下:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;

namespace SoftReg
{
/// <summary>
/// Summary description for UserDataGrid
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:UserDataGrid runat=server>")]
public class UserDataGrid:System.Web.UI.WebControls.DataGrid
{
private string text;
private SqlDataAdapter adp;
private DataSet ds;
private DataView view;
private string[] arritem;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
///
/// protect SortDirection 排序方向
///
public string SortDirection
{
get
{
if(ViewState["SortDirection"]==null)
{
return null;
}
else
{
if(ViewState["SortDirection"].ToString()=="")
{
return null;
}
else
{
return ViewState["SortDirection"].ToString();
}
}
}
set
{
ViewState["SortDirection"]=value;
}
}
///
/// protect SortField 排序字段
///
public string SortField
{
get
{
if(ViewState["SortField"]==null)
{
return null;
}
else
{
if(ViewState["SortField"].ToString()=="")
{
return null;
}
else
{
return ViewState["SortField"].ToString();
}
}
}
set
{
ViewState["SortField"]=value;
}
}
///
/// sql 查询字串
///
public string selectCommandText
{
get
{
if(ViewState["selectCommandText"]==null)
{
return null;
}
else
{
if(ViewState["selectCommandText"].ToString()=="")
{
return null;
}
else
{
return ViewState["selectCommandText"].ToString();
}
}
}
set
{
ViewState["selectCommandText"]=value;
}
}
///
/// 连接字串
///
public string selectConnectionString
{
get
{
if(ViewState["selectConnectionString"]==null)
{
return null;
}
else
{
return ViewState["selectConnectionString"].ToString();
}
}
set
{
ViewState["selectConnectionString"]=value;
}
}
public DataTable Bindtable;
public UserDataGrid()
{
this.Init+=new System.EventHandler(this.UserDataGrid_Init);
}
private void UserDataGrid_Init(object sender,EventArgs e)
{
this.Load+= new System.EventHandler(this.UserDataGrid_Load);
this.SortCommand+=new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.UserDataGrid_SortCommand);
this.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.UserDataGrid_ItemDataBound);
}
private void UserDataGrid_Load(object sender,EventArgs e)
{
this.HorizontalAlign=HorizontalAlign.Center;
this.AllowSorting=true;
arritem=new string[256];
ds=new DataSet();
}
///
/// GRID绑定
///
/// 查询字串
/// 连接字串
public void BindGrid(string selectCommandText,string selectConnectionString)
{
this.selectCommandText=selectCommandText;
this.selectConnectionString=selectConnectionString;
BindGrid();
}
///
/// grid绑定
///
/// 查询字串
/// 连接对象
public void BindGrid(string selectCommandText,SqlConnection cn)
{
this.selectCommandText=selectCommandText;
this.selectConnectionString=cn.ConnectionString;
BindGrid();
}
///
/// grid绑定,必须先设置 selectCommmandText 及SelectConnectionString 属性
///
public void BindGrid()
{
if(this.selectCommandText!=null&&this.selectConnectionString!=null)
{
adp=new SqlDataAdapter(this.selectCommandText,this.selectConnectionString);
adp.Fill(ds,"temp");
view=ds.Tables["temp"].DefaultView;
if(this.SortField!=null)
{
view.Sort=this.SortField+" "+this.SortDirection;
int sortfieldindex=0;
for( int i=0;i<=ds.Tables["temp"].Columns.Count-1;i++)
{
if(ds.Tables["temp"].Columns[i].ColumnName==this.SortField)
{
sortfieldindex=i;
break;
}
}
string SortDirectionImg="▲";
if(this.SortDirection==" DESC")
{
SortDirectionImg="▼";
}
if(this.SortField!=this.DataKeyField)
{
ds.Tables["temp"].Columns[sortfieldindex].ColumnName+=SortDirectionImg;
}
}
Bindtable=ds.Tables["temp"];
DataRow row=Bindtable.NewRow();
row[0]="总计:";
for(int i=1;i<=Bindtable.Columns.Count;i++)
{
Type t=Bindtable.Columns[i].DataType;
if(t==typeof(Decimal)||t==typeof(Double)||t==typeof(Int16)||t==typeof(Int32)||t==typeof(Int64)||t==typeof(UInt16)||t==typeof(UInt32)||t==typeof(Int64))
{
row[i]=0;
foreach( DataRow r in Bindtable.Rows)
{
try
{
row[i]=double.Parse(row[i].ToString())+double.Parse(r[i].ToString());
}
catch(Exception et)
{
throw new Exception(et.Message);
}
}
}
}
Bindtable.Rows.Add(row);
this.DataSource=view;
this.DataBind();
}
else
{

}
}
Truly 2005-01-14
  • 打赏
  • 举报
回复
切换一下Debug/Release编译成功后再切换回来
time_is_life 2005-01-14
  • 打赏
  • 举报
回复
你最好把代码贴出来,不然没有办法给你分析,还有,你的控件又没有用强名?
dotnet90 2005-01-14
  • 打赏
  • 举报
回复
把你编译成dll的源代码从项目中排除保证没有问题了
ldw701 2005-01-14
  • 打赏
  • 举报
回复
D:\WebSites\Test\TestVaildClient.aspx(12,31): error CS0433: The type 'SoftReg.UserDataGrid' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\Temporary ASP.NET Files\test\f0a45bd4\be3552d5\__code4pwrlsne.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\Temporary ASP.NET Files\test\f0a45bd4\be3552d5\assembly\dl2\v2_d67516a7\00905ccd_11fac401\UserDataGrid.dll'

救命啊。。。。。。。。
time_is_life 2005-01-14
  • 打赏
  • 举报
回复
可能是强名的问题
ldw701 2005-01-14
  • 打赏
  • 举报
回复
是在项目里,编译dll的时候没有问题,就是把这个控件添加到toolbox里面,再拉到页面上,编译工程的时候报这个错!
yitiaocheng_10 2005-01-14
  • 打赏
  • 举报
回复
编译是编译自定义控件的时候还是在你现在用这个自定义控件的项目里?
codehunter008 2005-01-14
  • 打赏
  • 举报
回复
删除你的BIN目录下的DLL试试!

62,046

社区成员

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

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

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

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