我需要替换用 MaskedEditExtender 包装的 TextBox 中的“_”字符,以在编辑 TextBox 时验证数据输入。
<asp:MaskedEditExtender ID="TextBox1_MaskedEditExtender" runat="server"
CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
InputDirection="RightToLeft" Mask="9999.9" MaskType="Number"
TargetControlID="TextBox1" ClearTextOnInvalid="False>
</asp:MaskedEditExtender>
当我尝试编辑行时。文本框值为 "__12.4" 。在 GridView1_RowUpdating 我试图用“”替换“_”而没有结果。
protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
{
TextBox Textbox1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Textbox1 ");
Label Label2 = new Label();
Label2.Text = TextBox1.Text.Replace("_", "");
GridView1.DataBind();
}
我的 TemplateField 看起来像这样
<asp:TemplateField HeaderText="Decimal Value" SortExpression="DecimalValue">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DecimalValue","{0:F1}") %>' Height="20px" MaxLength="6" Width="40px"></asp:TextBox>
<%-- Formated to display 9999.9 per requirement --%>
<asp:MaskedEditExtender ID="TextBox1_MaskedEditExtender" runat="server"
CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
InputDirection="RightToLeft" Mask="9999.9" MaskType="Number"
TargetControlID="TextBox1" ClearTextOnInvalid="False">
</asp:MaskedEditExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DecimalValue", "{0:F1}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
我不知道在更新行后在哪里更新 TextBox1.text 值并将其发送到 MS SQL 数据库。