如何访问位于从codebehind在ListView控件? [英] How to access controls located in the listview from codebehind?

查看:128
本文介绍了如何访问位于从codebehind在ListView控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ListView的 CouncilListView 和一个名为文本框 EmailTextBox 这是在ListView。

我怎样才能访问该文本框从C $ cBehind的$?

我尝试了一些形式的的FindControl 这样的:

  this.Page.FindControl(EmailTextBox);
this.Page.FindControl(CouncilListView)的FindControl(EmailTextBox);
this.CouncilListView.Findcontrol(EmailTextBox);
this.FindControl(EmailTextBox);
 

但我得到这个错误:

  

对象引用未设置到对象的实例。

解决方案

我解决了这种方式:

 保护无效CouncilListView_ItemInserted(对象发件人,ListViewInsertedEventArgs E)
{
    的foreach(的DictionaryEntry Emailentry在e.Values​​)
    {
        如果(Emailentry.Key ==电子邮件)//表字段名称是电子邮件
        {
            message.To.Add(新MailAddress(Emailentry.Value.ToString()));
        }
    }
}
 

I have a ListView called CouncilListView and a TextBox called EmailTextBox which is in the ListView.

How can I access this TextBox from the CodeBehind?

I tried some forms of FindControl like :

this.Page.FindControl("EmailTextBox");
this.Page.FindControl("CouncilListView").FindControl("EmailTextBox");
this.CouncilListView.Findcontrol("EmailTextBox");
this.FindControl("EmailTextBox");

but I get this error:

Object reference not set to an instance of an object.

解决方案

I solved it this way:

protected void CouncilListView_ItemInserted(Object sender, ListViewInsertedEventArgs e)
{
    foreach (DictionaryEntry Emailentry in e.Values)
    {
        if (Emailentry.Key == "Email") //table field name is "email"
        {
            message.To.Add(new MailAddress(Emailentry.Value.ToString()));
        }
    }
}

这篇关于如何访问位于从codebehind在ListView控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆