中继器内的屏蔽编辑扩展器

发布于 2024-08-26 14:32:09 字数 1225 浏览 13 评论 0原文

我如何在面板内动态创建文本框和蒙版编辑扩展器。 我的代码是这样的: 在 ASPX 页面中:

<asp:Repeater Id = "Repeater1" runat="server" DataSource="Function1" OnitemDataBound="ShowProducts_OntemDataBound">
<ItemTemplate>
<asp: Panel Id= "Panel1" runat="server">
<cc1:MaskedEditExtender Id="MskEdit" Mask="(999)-999-9999">
</cc1:MaskedEditExtender>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>

在 Aspx.Cs 页面中

Private DataView Function1()
{
Dataview dv =new dataview();
return dv;
}

    Private void ShowProducts_OntemDataBound(object sender, RepeaterEventItem e)
{
//Consider For the First Iteration of the Repeater I am Creating a Simple Text Box Dynamically
Textbox txt = new textbox();
txt.Text = "8888888888";
txt.Id = "TextBox1";

//Consider For the Second Iteration of the Repeater I am Creating another TextBox and a 
Textbox txt1 = new textBox();
txt1.text="2223334444";
txt1.Id = "TextBox2";

MaskedEditExtender mskEdit = (MaskedEditExtender)e.Item.FindControl("MskEdit");
mskEdit.TargetControlId = txt1.Id;

Panel panel1 = (Panel)e.item.Findcontrol("Panel1");
panel1.Controls.Add(txt1);
}

运行上述代码时,它给我“MaskedEditExtender 的空引用异常”。请建议我一些方法。

How can i dynamically create a textBox and a Masked Edit extender inside a Panel.
My code is something like this:
In the ASPX page:

<asp:Repeater Id = "Repeater1" runat="server" DataSource="Function1" OnitemDataBound="ShowProducts_OntemDataBound">
<ItemTemplate>
<asp: Panel Id= "Panel1" runat="server">
<cc1:MaskedEditExtender Id="MskEdit" Mask="(999)-999-9999">
</cc1:MaskedEditExtender>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>

In the Aspx.Cs page

Private DataView Function1()
{
Dataview dv =new dataview();
return dv;
}

    Private void ShowProducts_OntemDataBound(object sender, RepeaterEventItem e)
{
//Consider For the First Iteration of the Repeater I am Creating a Simple Text Box Dynamically
Textbox txt = new textbox();
txt.Text = "8888888888";
txt.Id = "TextBox1";

//Consider For the Second Iteration of the Repeater I am Creating another TextBox and a 
Textbox txt1 = new textBox();
txt1.text="2223334444";
txt1.Id = "TextBox2";

MaskedEditExtender mskEdit = (MaskedEditExtender)e.Item.FindControl("MskEdit");
mskEdit.TargetControlId = txt1.Id;

Panel panel1 = (Panel)e.item.Findcontrol("Panel1");
panel1.Controls.Add(txt1);
}

When running the above code it is giving me "Null Reference Exception for MaskedEditExtender".Please suggest me some way for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2024-09-02 14:32:09

检查 e.ItemFindControl("MskEdit") 是否不为空,因为在页眉、页脚行中,它将是空的。
这是代码:


if(e.Item.FindControl("MskEdit")!=null)
{
MaskedEditExtender mskEdit = (MaskedEditExtender)e.Item.FindControl("MskEdit"); mskEdit.TargetControlId = txt1.Id;
}

place a check if e.ItemFindControl("MskEdit") is not null, because in header, footer rows, it will be.
here is the code:


if(e.Item.FindControl("MskEdit")!=null)
{
MaskedEditExtender mskEdit = (MaskedEditExtender)e.Item.FindControl("MskEdit"); mskEdit.TargetControlId = txt1.Id;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文