我尝试在asp.net中发送电子邮件。当管理员选中复选框时,他/她能够将邮件发送到相应的电子邮件ID,并且电子邮件也存储在用户表中的数据库中。但是当我构建代码时,它向我显示错误
代码是
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkAll =
(CheckBox)Repeateremail.HeaderRow.FindControl("chkSelectAll");
if (chkAll.Checked == true)
{
foreach (GridViewRow gvRow in Repeateremail.Items)
{
CheckBox chkSel =
(CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = true;
}
}
else
{
foreach (GridViewRow gvRow in Repeateremail.Items)
{
CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = false;
}
}
}
在这条线
CheckBox chkAll =
(CheckBox)Repeateremail.HeaderRow.FindControl("chkSelectAll");
它向我显示标题错误
'System.Web.UI.WebControls.Repeater'不包含'HeaderRow'的定义,并且找不到扩展方法'HeaderRow'接受类型为'System.Web.UI.WebControls.Repeater'的第一个参数(您是缺少using指令或程序集
引用?)
在html中我在标头模板中这样使用
<td>
Check
<asp:CheckBox ID="chkSelectAll" runat="server"
AutoPostBack="true"
OnCheckedChanged="chkSelectAll_CheckedChanged"/>
Send Mail To All ?
</td>
并在项目模板中
<td>
<asp:CheckBox ID="chkSelect" runat="server"/>
</td>
您不需要使用该FindControl()
方法,因为无论如何您都在为要检查属性值的控件处理click事件,请尝试以下方法:
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
// Cast the sender to a CheckBox type
CheckBox chkAll = sender as CheckBox;
// The as operator will return null if the cast is not successful,
// so check for null before we try to use it
if(chkAll != null)
{
if (chkAll.Checked == true)
{
foreach (GridViewRow gvRow in Repeateremail.Items)
{
CheckBox chkSel =
(CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = true;
}
}
else
{
foreach (GridViewRow gvRow in Repeateremail.Items)
{
CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = false;
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句