I have a Masked edit extender in my gridview. I am displaying this gridview dynamically based on types, If the type is "T" it displays only textbox, if the type is "DT" it displays textbox with calendar.
I am using the same textbox, and in grid row databound event, I am hiding and showing the calendar button. But if I give the maskededitextender in the gridview, the mask is being applied for the nondate fields also.
I tried by giving a dummy textbox and make it as targetcontrolid for the maskededtextender and in rowdatabound event, I am setting the targetcontrolid of the maskededitextender to my textbox if the type is date. But it is not working.
can anyone please help me on this?
What I have tried:
Below is the rowdatabound event code:
protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
MaskedEditExtender ME = (MaskedEditExtender)e.Row.FindControl("MaskedEditExtender1");
TextBox txtValue1 = (TextBox)e.Row.FindControl("txtValue1");
TextBox txttest = (TextBox)e.Row.FindControl("txttest");
HiddenField hfInputType = (HiddenField)e.Row.FindControl("hfInputType");
ImageButton imgBtnFromDate = (ImageButton)e.Row.FindControl("imgBtnFromDate");
ME.TargetControlID = txttest.ClientID;
if(hfInputType.Value=="DT")
{
txtValue1.Style.Add(HtmlTextWriterStyle.Display, "block");
imgBtnFromDate.Style.Add(HtmlTextWriterStyle.Display, "block");
ME.TargetControlID = txtValue1.ClientID;
}
else if(hfInputType.Value=="U")
{
txtValue1.Style.Add(HtmlTextWriterStyle.Display, "block");
imgBtnFromDate.Style.Add(HtmlTextWriterStyle.Display, "none");
}
}
}
}
Asp.net code:
<asp:ImageButton ID="imgBtnFromDate" runat="server" Style="display: none" ImageUrl="~/App_Themes/Black/Images/Calendar.png" />
<cc1:CalendarExtender ID="ceFromDate" PopupButtonID="imgBtnFromDate" runat="server"
TargetControlID="txtValue1">
<cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" AcceptNegative="Left"
DisplayMoney="Left" Mask="99/99/9999" MaskType="Date" MessageValidatorTip="true"
>