gpt4 book ai didi

c# - 在 Asp.Net 中使用复选框发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 13:32:49 25 4
gpt4 key购买 nike

我尝试在 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' does not contain a definition for 'HeaderRow' and no extension method 'HeaderRow' accepting a first argument of type 'System.Web.UI.WebControls.Repeater' could be found (are you missing a using directive or an assembly
reference?)

在 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() 方法,因为您正在处理要检查其属性值的控件的点击事件,请试试这个:

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;
}
}
}
}

关于c# - 在 Asp.Net 中使用复选框发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19913806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com