开发者

How to update computed column in gridview immediately without in edit mode?

i use autopost in itemtemplate, but it do not update the result column immediately

i guess to use multiplier_dropdownlist_SelectedIndexChanged to update gridview, but there is no gridview.update(); how to update displayed result immediately

[Solved]

  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.DataSo开发者_C百科urce = storeview;
            Calculator_GridView.DataBind();
        }


keep the gridview inside an ajax update panel.after the content template of ajax control pane use a timer control which will periodically update ur gridview automatically

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜