[英]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.