简体   繁体   English

从文本框更新编辑模式下的GridView行

[英]Updating GridView row in edit mode from text box

I need to replace "_" character from my TextBox which is wraped with MaskedEditExtender to validate data entry when editing TextBox. 我需要在TextBox中替换“_”字符,该字符包含MaskedEditExtender以在编辑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>

When I try to edit row. 当我尝试编辑行时。 Textbox value is "__12.4" . 文本框值为“__12.4”。 In GridView1_RowUpdating I am trying to replace "_" with "" with no results. 在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();
    }

My TemplateField looks like this 我的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>

I don't know where to update TextBox1.text value after row is update and send this to MS SQL database. 我不知道在更新行之后更新TextBox1.text值的位置并将其发送到MS SQL数据库。

I think the problem is when you select the row, becouse you select the row, take the textbox but never change the value: 我认为问题是当你选择行时,因为你选择了行,采取文本框但从不更改值:

    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 = GridView1.Text.Replace("_", "");
    GridView1.DataBind();
}

I think is (see code below) 我认为是(见下面的代码)

    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("_", ""); //Replace Gridview for the text box
    GridView1.DataBind();
}

But here only you'll replace the Character and put in a Label, it won't be update the texbox. 但是这里只有你将替换Character并放入Label,它不会更新texbox。

Cheer 欢呼

you dont need to databind your gridview in rowupdating if you have a datasource handling updates for you, can you try this and see what happens? 如果你有一个数据源处理更新,你不需要在rowupdating中数据化你的gridview,你能试试看看会发生什么吗?

protected void GridView1_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
{
    TextBox Textbox1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Textbox1");
    Textbox1.Text = Regex.Replace(Textbox1.Text, "_", "");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM