0

我的页面上有一个gridview,有三列,一列是数量,我需要将MaskEditExtender 与简单的TextBox 一起使用,但它只在第一行工作,从第二行开始,文本框出现时没有掩码。

这是我的代码:

<Columns>                        
<asp:TemplateField HeaderText="Qty">
    <ItemTemplate>

        <asp:TextBox ID="txtQuan" runat="server" ValidationGroup="MKE" MaxLength="5" 
              style="text-align:right" width="100px" Text='<%# BIND("QUAN") %>' />
        <ajaxToolkit:MaskedEditExtender ID="txtQuan_MaskedEditExtender" runat="server"
            Enabled="True" Mask="99999" TargetControlID="txtQuan" />

    </ItemTemplate>
</asp:TemplateField>

4

2 回答 2

0

Reason is that When Gridview Render row each Row contain textbox with deffferent autogenerated id and you are given a fixed name in TargetControlID Property in MaskEditExtender . so you need to use RowDataBound Event to Put MaskEditExtender in each textbox....

于 2013-06-22T11:42:01.637 回答
0
using AjaxControlToolkit;                                                              protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox txt = (TextBox)e.Row.FindControl("txtQuan");
            MaskedEditExtender mxt = (MaskedEditExtender)e.Row.FindControl("MaskedEditExtender1");
            mxt.TargetControlID = txt.ID;
        }
    }
于 2013-06-22T11:55:15.677 回答