如何在gridview中立即更新计算列而不处于编辑模式

本文关键字:于编辑 模式 编辑 gridview 计算 更新 | 更新日期: 2023-09-27 17:49:47

我在itemtemplate中使用autopost,但它不会立即更新结果列

我猜使用multiplier_dropdownlist_SelectedIndexChanged来更新gridview,但是没有gridview.update();如何立即更新显示的结果

(解决)

  protected void Timer1_Tick(object sender, EventArgs e)
            {
                for (int i = 0; i < Calculator_GridView.Rows.Count; i++)
                {
                    string serial_no = Calculator_GridView.Rows[i].Cells[1].Text;
                    string a1_textbox = Calculator_GridView.Rows[i].Cells[2].Text;
                    string b1_textbox = Calculator_GridView.Rows[i].Cells[3].Text;
                    DropDownList mp_dropdown = (DropDownList)Calculator_GridView.Rows[i].Cells[4].Controls[1];
                    //TextBox Result_textbox = (TextBox)Calculator_GridView.Rows[e.RowIndex].Cells[5].Controls[0];

                string executestring = "";
                executestring = "Update cal set a1=" + a1_textbox;
                executestring = executestring + ", b1=" + b1_textbox;
                executestring = executestring + ", mp=" + mp_dropdown.SelectedValue;
                executestring = executestring + ", result=" + (Convert.ToDouble(mp_dropdown.SelectedValue) * Convert.ToDouble(b1_textbox)).ToString();
                executestring = executestring + " where [識別碼]=" + serial_no;
                ExecuteDatabase(executestring);
            }
            string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/db1.mdb";
            OleDbConnection conn = new OleDbConnection(connstr);
            conn.ConnectionString = connstr;
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                conn.Close();
            }
            OleDbCommand get_info_cmd = null;
            get_info_cmd = new OleDbCommand("SELECT [識別碼], [a1], [b1], [result], [mp] FROM [cal]", conn);
            OleDbDataReader get_info_Reader = get_info_cmd.ExecuteReader();
            store.Columns.Add(new DataColumn("識別碼", typeof(int)));
            store.Columns.Add(new DataColumn("a1", typeof(double)));
            store.Columns.Add(new DataColumn("b1", typeof(double)));
            store.Columns.Add(new DataColumn("mp", typeof(double)));
            store.Columns.Add(new DataColumn("result", typeof(double)));
            DataRow dr;
            try
            {
                while (get_info_Reader.Read())
                {
                    dr = store.NewRow();
                    dr[0] = get_info_Reader["識別碼"].ToString();
                    dr[1] = get_info_Reader["a1"].ToString();
                    dr[2] = get_info_Reader["b1"].ToString();
                    dr[3] = get_info_Reader["mp"].ToString();
                    dr[4] = (Convert.ToDouble(get_info_Reader["b1"].ToString()) * Convert.ToDouble(get_info_Reader["mp"].ToString())).ToString();
                    store.Rows.Add(dr);
                }
            }
            catch (Exception ex)
            {
                Error_Label.Text = Error_Label.Text + ex.ToString();
                conn.Close();
            }
            finally
            {
                get_info_cmd.Dispose();
                get_info_Reader.Close();
                conn.Close();
            }
            storeview = new DataView(store);
            Calculator_GridView.Font.Size = new FontUnit(10);
            Calculator_GridView.DataSourceID = "";
            Calculator_GridView.DataSource = storeview;
            Calculator_GridView.DataBind();
        }

如何在gridview中立即更新计算列而不处于编辑模式

将gridview保留在ajax更新面板中。在ajax控件面板的内容模板之后,使用计时器控件,它将定期自动更新gridview