开发者

Masked Edit extender inside a Repeater

开发者 https://www.devze.com 2022-12-24 03:35 出处:网络
How can i dynamically create a textBox and a Masked Edit extender inside a Panel. My code is something like this:

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

开发者_如何学GoPrivate 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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号