Как получить значение при движении курсора?
Привет...
У меня есть три текстовых поля на динамическом добавлении строк.
Первые два предназначены для ввода чисел для умножения.
И третий - для отображения результата умножения.
Я хочу, чтобы результат умножения появился в третьем текстовом поле, как только я войду
цифры в первых двух текстовых полях, не нажимая никаких кнопок и даже не нажимая 3 текстовых поля .
Кто-нибудь знает, как это сделать?
Что я уже пробовал:
private void SetInitialRow() { string lit1 = "First"; string lit2 = "units @ Rs."; //string lit3 = "= Rs."; string lit3 = "=Rs1."; DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("First", typeof(string))); dt.Columns.Add(new DataColumn("Column2", typeof(string))); dt.Columns.Add(new DataColumn("Second", typeof(string))); dt.Columns.Add(new DataColumn("Column4", typeof(string))); dt.Columns.Add(new DataColumn("Third", typeof(string))); dt.Columns.Add(new DataColumn("Column6", typeof(string))); // dt.Columns.Add(new DataColumn("fourth", typeof(string))); //dt.Columns.Add(new DataColumn("Column8", typeof(string))); dr = dt.NewRow(); dr["First"] = lit1; dr["Column2"] = string.Empty; dr["Second"] = lit2; dr["Column4"] = string.Empty; dr["Third"] = lit3; dr["Column6"] = string.Empty; // dr["fourth"] = lit4; // dr["Column8"] = string.Empty; dt.Rows.Add(dr); //dr = dt.NewRow(); //Store the DataTable in ViewState ViewState["tbl_site_da_electricity"] = dt; Gridview1.DataSource = dt; Gridview1.DataBind(); } protected void ButtonAdd_Click(object sender, EventArgs e) { AddNewRowToGrid(); } private void AddNewRowToGrid() { int rowIndex = 0; string lit1 = "Next"; string lit2 = "units @ Rs."; //string lit3 = "= Rs."; string lit3 = "=Rs1."; if (ViewState["tbl_site_da_electricity"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["tbl_site_da_electricity"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("tb_first"); TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("tb_rupees"); // TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[5].FindControl("tb_rowTotal"); TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[5].FindControl("tb_rowTotal1"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["First"] = lit1; dtCurrentTable.Rows[i - 1]["Column2"] = box1.Text; drCurrentRow["Second"] = lit2; dtCurrentTable.Rows[i - 1]["Column4"] = box2.Text; drCurrentRow["Third"] = lit3; dtCurrentTable.Rows[i - 1]["Column6"] = box3.Text; //drCurrentRow["fourth"] = lit4; // dtCurrentTable.Rows[i - 1]["Column8"] = box4.Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState["tbl_site_da_electricity"] = dtCurrentTable; Gridview1.DataSource = dtCurrentTable; Gridview1.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on Postbacks SetPreviousData(); } private void SetPreviousData() { int rowIndex = 0; if (ViewState["tbl_site_da_electricity"] != null) { DataTable dt = (DataTable)ViewState["tbl_site_da_electricity"]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("tb_first"); TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("tb_rupees"); // TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[5].FindControl("tb_rowTotal"); TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[5].FindControl("tb_rowTotal1"); box1.Text = dt.Rows[i]["Column2"].ToString(); box2.Text = dt.Rows[i]["Column4"].ToString(); box3.Text = dt.Rows[i]["Column6"].ToString(); // box4.Text = dt.Rows[i]["Column8"].ToString(); rowIndex++; } } } } protected void tb_rupees_TextChanged(object sender, EventArgs e) { int rowIndex = 0; DataTable dt = (DataTable)ViewState["tbl_site_da_electricity"]; int abc = 0; int aa = 0; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("tb_first"); TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("tb_first"); TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("tb_rupees"); TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[5].FindControl("tb_rowTotal1"); TextBox box4 = (TextBox)Gridview1.FooterRow.Cells[1].FindControl("tb_Total_Unit"); TextBox box5 = (TextBox)Gridview1.FooterRow.Cells[5].FindControl("tb_alowdTotal"); //char executive, superviser, workers; int a = 0, b = 0; a = Convert.ToInt32(box1.Text); b = Convert.ToInt32(box2.Text); aa = aa + Convert.ToInt32(box1.Text); if (tb_designation.Text.ToString() == "executive") { if (aa <= 300) { box3.Text = (a * b).ToString(); abc = abc + Convert.ToInt32(box3.Text); } else { aa = aa - Convert.ToInt32(box1.Text); box3.Text = ((300 - aa) * b).ToString(); abc = abc + Convert.ToInt32(box3.Text); aa = 300; } } else if (tb_designation.Text.ToString() == "supervisor") { if (aa <= 250) { box3.Text = (a * b).ToString(); abc = abc + Convert.ToInt32(box3.Text); } else { aa = aa - Convert.ToInt32(box1.Text); box3.Text = ((250 - aa) * b).ToString(); abc = abc + Convert.ToInt32(box3.Text); aa = 250; } } else if (tb_designation.Text.ToString() == "workers") { if (aa <= 200) { box3.Text = (a * b).ToString(); abc = abc + Convert.ToInt32(box3.Text); } else { aa = aa - Convert.ToInt32(box1.Text); box3.Text = ((200 - aa) * b).ToString(); abc = abc + Convert.ToInt32(box3.Text); aa = 200; } } box4.Text = aa.ToString(); box5.Text = abc.ToString(); rowIndex++; } } }
<pre><% <fieldset> <asp:UpdatePanel ID="updPanelelectricity" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:GridView ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false" GridLines="None" > <Columns> <asp:BoundField DataField="First" /> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="tb_first" runat="server" Width="50px" autocomplete="off" ></asp:TextBox></ItemTemplate> <FooterTemplate> <asp:TextBox ID="tb_Total_Unit" runat="server" Width="50px" ></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:BoundField DataField="Second" /> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="tb_rupees" runat="server" Width="50px" AutoPostBack="True" OnTextChanged="tb_rupees_TextChanged"></asp:TextBox></ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Third" /> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="tb_rowTotal1" runat="server" Width="50px" ></asp:TextBox></ItemTemplate> <FooterTemplate> <asp:TextBox ID="tb_alowdTotal" runat="server" Width="50px" ></asp:TextBox></FooterTemplate> </asp:TemplateField> <asp:TemplateField> <FooterTemplate> <asp:Button ID="ButtonAdd" runat="server" Text="Add" OnClick="ButtonAdd_Click" /> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> </fieldset>