如何把一个对象传进用户控件中?

teachman_999 2006-11-07 01:57:29
rt
...全文
143 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
PCHWBANK 2006-11-08
  • 打赏
  • 举报
回复
楼上的都正解
daishengs 2006-11-08
  • 打赏
  • 举报
回复
一般用属性
hero4u 2006-11-08
  • 打赏
  • 举报
回复
晕了
可以创建
private object a
public object b
{
get{return a;}
}
呵呵
ShengNet 2006-11-07
  • 打赏
  • 举报
回复
序列化
teachman_999 2006-11-07
  • 打赏
  • 举报
回复
好的,这是我刚刚练习做的一个用户控件,其中有两个dropdownlist,一个是部门,一个组别
其中这句
RelationddList = (UserControl_SelectSection)((System.Web.UI.Page)this.Parent.Page).FindControl(RelationddList_Name); 已经解决我上面的问题.
但是在这里:
if (RelationddList != null)
{
RelationddList.SectionValue = this.DropDownList_Section.SelectedValue;
}

会报如下错误:Cannot have multiple items selected in a DropDownList.
找了半天没有什么发现



public partial class UserControl_SelectSection : System.Web.UI.UserControl
{

protected string sSql = "";
protected string RelationddList_Name="";
protected UserControl_SelectSection RelationddList;

//public delegate void OnSectionChanged(object sender, System.EventArgs e);
//public event OnSectionChanged onSectionChanged;

#region "属性"

public int Width
{

set
{
this.DropDownList_Section.Width = value;
this.DropDownList_Line.Width = value;
}
}

public bool SectionAutoPostBack
{
set
{
this.DropDownList_Section.AutoPostBack = value;

}

}

public bool LineAutoPostBack
{
set
{
this.DropDownList_Line.AutoPostBack = value;

}

}
public string SectionValue
{
get { return this.DropDownList_Section.SelectedValue; }
set
{

this.DropDownList_Section.Items.FindByValue(value.ToString()).Selected = true;
// this.DropDownList_Section.SelectedValue = value.ToString();

}

}
public string LineValue
{
get { return this.DropDownList_Line.SelectedValue; }
set
{

this.DropDownList_Line.Items.FindByValue(value.ToString()).Selected = true;
// this.DropDownList_Line.SelectedValue = value.ToString();
}

}

public string RddList_Name
{
set
{
RelationddList_Name = value.ToString();
}

}

#endregion

#region "方法"
private void FindRelationControl()
{

RelationddList = (UserControl_SelectSection)((System.Web.UI.Page)this.Parent.Page).FindControl(RelationddList_Name);

}

#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();

}
if (RelationddList_Name != "")
FindRelationControl();
}



protected void BindData()
{

System.Data.DataSet dsTemp;
WebMISCL.ClassDB myClsDB = new WebMISCL.ClassDB();
string sSql = "";

ListItem type_all = new ListItem("ALL", "");
DropDownList_Section.Items.Add(type_all);
DropDownList_Line.Items.Add(type_all);

dsTemp = new DataSet();
sSql = "select distinct section_code, rtrim(section_code) + '-' + struct_name struct_name from HR_ORGANIZATION_CODES where struct_type = 'S' order by section_code";
dsTemp = myClsDB.ExecuteDataset(CommandType.Text, sSql);
DataView dv_temp_section = new DataView(dsTemp.Tables[0]);
for (int i = 0; i < dv_temp_section.Count; i++)
{
ListItem li = new ListItem(dv_temp_section[i]["struct_name"].ToString(), dv_temp_section[i]["section_code"].ToString());
DropDownList_Section.Items.Add(li);


}

dsTemp = new DataSet();
sSql = "select distinct line_code, rtrim(section_code)+'-'+rtrim(line_code) + '-' + struct_name struct_name from HR_ORGANIZATION_CODES where struct_type = 'L' order by line_code";
dsTemp = myClsDB.ExecuteDataset(CommandType.Text, sSql);
DataView dv_temp_line = new DataView(dsTemp.Tables[0]);

for (int i = 0; i < dv_temp_line.Count; i++)
{
ListItem li = new ListItem(dv_temp_line[i]["struct_name"].ToString(), dv_temp_line[i]["line_code"].ToString());
DropDownList_Line.Items.Add(li);

}
myClsDB.CloseConnection();
myClsDB.Dispose();
}

protected void DropDownList_Section_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList_Line.Items.Clear();

System.Data.DataSet dsTemp;
string sSql = "";
ListItem type_all = new ListItem("ALL", "");

DropDownList_Line.Items.Add(type_all);

WebMISCL.ClassDB myClsDB = new WebMISCL.ClassDB();

dsTemp = new DataSet();
sSql = "select distinct line_code, rtrim(section_code)+'-'+rtrim(line_code) + '-' + struct_name struct_name from HR_ORGANIZATION_CODES where struct_type = 'L' and section_code like '%" + DropDownList_Section.SelectedValue.ToString() + "%' order by line_code";
dsTemp = myClsDB.ExecuteDataset(CommandType.Text, sSql);
myClsDB.CloseConnection();
myClsDB.Dispose();

DataView dv_temp_line = new DataView(dsTemp.Tables[0]);
for (int i = 0; i < dv_temp_line.Count; i++)
{
ListItem li = new ListItem(dv_temp_line[i]["struct_name"].ToString(), dv_temp_line[i]["line_code"].ToString());
DropDownList_Line.Items.Add(li);

}
myClsDB.CloseConnection();
myClsDB.Dispose();

if (RelationddList != null)
{
//RelationddList.SectionValue = this.DropDownList_Section.SelectedValue;
}
}
liujia_0421 2006-11-07
  • 打赏
  • 举报
回复
用属性不行吗?

楼主遇到的是什么问题,能具体说下吗?
teachman_999 2006-11-07
  • 打赏
  • 举报
回复
来个正确点答案看看
jun-2013 2006-11-07
  • 打赏
  • 举报
回复
public 对象类名 AA
{
get {return _AA;}
set { _AA=value;}
}
teachman_999 2006-11-07
  • 打赏
  • 举报
回复
我是想把一个页面中的控件引用进用户控件中
冷月孤峰 2006-11-07
  • 打赏
  • 举报
回复
public string AA
{
get {return _AA;}
set { _AA=value;}
}
用属性。

62,046

社区成员

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

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

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

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