当前位置: 代码迷 >> ASP.NET >> 用户控件中取值的有关问题
  详细解决方案

用户控件中取值的有关问题

热度:4604   发布时间:2013-02-26 00:00:00.0
求助用户控件中取值的问题
在DataGrid中添加一列为模板列,模板列中放置一个CheckBox.
然后将该DataGrid保存为一用户控件.
在一个ASP.NET页中使用上述控件,问题是如何取出该控制中选中的项呢?

------解决方案--------------------------------------------------------
做成公用属性或方法如:public string GetSelectedId(){ ///}
------解决方案--------------------------------------------------------
CheckBox tb=(CheckBox)e.Item.FindControl(string id);
------解决方案--------------------------------------------------------
在用户控件里设一个属性,取得checkbox的值
------解决方案--------------------------------------------------------
public string str
{
get
{ return str;}
set
{
foreach(DataGridItem dl in this.DataGrid1.Items)
{
CheckBox chk=(CheckBox)dl.FindControl( "chk ");
if(chk.Checked)
{
str=....;
}

}
}
  相关解决方案