简体   繁体   English

我在gridview中有3个文本框。 当输入值到第一个和第二个文本框时,我想自动将结果写入第三个文本框

[英]i have 3 textboxes in gridview. When value is entered to first and second textboxes i want automatically write result to third textbox

i have 3 textboxes in gridview. 我在gridview中有3个文本框。 When value is entered to first and second textboxes i want automatically write result to third textbox. 当输入值到第一个和第二个文本框时,我想自动将结果写入第三个文本框。

this is my gridview: 这是我的gridview:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Width="892px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:TemplateField HeaderText="Ales Puanı">  
            <ItemTemplate>  
                <asp:TextBox ID="Txt_Ales" runat="server" Text='<%#Eval("alesSinavPuani") %>'></asp:TextBox>  
            </ItemTemplate>  
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Dil Puanı">  
            <ItemTemplate>  
                <asp:TextBox ID="txt_Dil" runat="server" Text='<%#Eval("dilSinavPuani") %>'></asp:TextBox>  
            </ItemTemplate>  
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Toplam">  
            <ItemTemplate>  
                <asp:Label ID="lbl_Toplam" runat="server" ></asp:Label>  
            </ItemTemplate> 
        </asp:TemplateField>
    </Columns>
</asp:GridView>

1) Mention AutoPostBack="true" for 2 textbox's 2) Mention event OnTextChanged="Txt_TextChanged" for 2 textbox's 3) In TextChanged Event access the controls, find the result logic and assign to the 3rd control. 1)提及2个文本框的AutoPostBack =“true”2)提及事件OnTextChanged = 2个文本框的“Txt_TextChanged”3)在TextChanged事件中访问控件,找到结果逻辑并分配给第3个控件。 In this case, 3rd control is mentioned as Label. 在这种情况下,第3个控件被称为Label。 It can be Textbox also. 它也可以是文本框。

ASPX Code ASPX代码

<asp:GridView ID="GridView1" runat="server" CellPadding="3" Width="892px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellSpacing="2">
                <Columns>
                    <asp:TemplateField HeaderText="Ales Puanı">
                        <ItemTemplate>
                            <asp:TextBox ID="Txt_Ales" runat="server" Text='<%#Eval("alesSinavPuani") %>' OnTextChanged="Txt_TextChanged" AutoPostBack="true"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Dil Puanı">
                        <ItemTemplate>
                            <asp:TextBox ID="txt_Dil" runat="server" Text='<%#Eval("dilSinavPuani") %>'  OnTextChanged="Txt_TextChanged" AutoPostBack="true"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Toplam">
                        <ItemTemplate>
                            <asp:Label ID="lbl_Toplam" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

TextChange Event Code TextChange事件代码

 protected void Txt_TextChanged(object sender, EventArgs e)
        {
            TextBox Txt_Ales = GridView1.Rows[((sender as TextBox).NamingContainer as GridViewRow).RowIndex].FindControl("Txt_Ales") as TextBox;
            TextBox txt_Dil = GridView1.Rows[((sender as TextBox).NamingContainer as GridViewRow).RowIndex].FindControl("txt_Dil") as TextBox;
            Label lbl_Toplam = GridView1.Rows[((sender as TextBox).NamingContainer as GridViewRow).RowIndex].FindControl("lbl_Toplam") as Label;

            int num1, num2 = 0;
            if (Txt_Ales != null && txt_Dil != null && lbl_Toplam != null)
            {
                int.TryParse(Txt_Ales.Text, out num1);
                int.TryParse(txt_Dil.Text, out num2);
                lbl_Toplam.Text = (num1 + num2).ToString();
            }
        }

暂无
暂无

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

相关问题 我想添加两个或更多文本框的值 - I want to Add the value of two or more textboxes 每次我按下按钮时,我希望它指示 C# 中我的文本框或文本框何时为空 - Evertime I press a button I want it to indicate when my textbox or textboxes are empty in C# 当我尝试解析的文本框中未输入任何内容时,应用程序崩溃 - App crashes when nothing is entered in the TextBoxes I'm trying to parse 如果我输入其他文本框,则取消文本框 - Canceling textboxes if I type in other textbox 我正在创建帐单。 在那我在gridview中添加了文本框和下拉列表。 现在在textbox1中,我想从数据库中获取价格。 - I am creating billing form. In that i added textbox and dropdownlist in gridview. now in textbox1 i want to fetch price from database. 我有 2 个文本框,textbox1 有固定时间“HH:mm”,Textbox2 应该有 textbox1 时间加 10 分钟 - I have 2 textboxes , textbox1 has a fixed time " HH:mm", Textbox2 should have textbox1 time plus 10 minutes 带文本框的gridview - gridview with textboxes 从两个文本框中添加值并在第三个文本框 3 中显示总和,但在第三个文本框中显示第一个或第二个文本框的值 - Add values from two textboxes and display the sum in third textbox 3 but value of 1st aor 2nd textbox show in third textbox 我想检查在Data gridview中输入的值是否已经存在? - I want to check the value entered in Data gridview is already exist or not? 如何动态地将指定数量的文本框添加到gridview? - How do I dynamically add specified number of textboxes to gridview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM