0

我在模板字段中有一个下拉列表,它在加载时选择的值设置为 gridview 中的另一个字段。在 rowupdating 事件中,下拉菜单返回到初始选定值并且不保留新值。我有填充网格的方法,该方法包含在 page_load 事件的 if this.page.IsPostBack 中。如何在 rowupdating 事件期间绑定控件的新选定值并忽略它的初始数据绑定?

我也将自动回发属性设置为 true。

这是 rowupdating 事件(我实际上是插入到另一个表中而不是更新这个网格)

protected void grd_add_bins__RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = (GridViewRow)grd_add_bins.Rows[e.RowIndex];
            //int id = Int32.Parse(grdBins.DataKeys[e.RowIndex].Value.ToString());

            Label room1 = (Label)row.FindControl("grd_add_room");
            Label grower1 = (Label)row.FindControl("grd_add_grower_id");
            TextBox bins1 = (TextBox)row.FindControl("grd_add_txtbins_to_pack");
            DropDownList packas1 = (DropDownList)row.FindControl("grd_add_ddl_pack_as");
            TextBox block1 = (TextBox)row.FindControl("grd_add_txt_block");
            Label pool1 = (Label)row.FindControl("grd_add_pool");

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "insert into t_run_schedule_lots  " +
                              "(record_key,room_id,grower_id,block_id,pool_id,total_bins,pack_as) " +
                              "values (@rec_id,@room,@grower,@block,@pool,@bins,@pack_as)";

            cmd.Parameters.Add("@rec_id", SqlDbType.VarChar).Value = lblRec_key.Text;
            cmd.Parameters.Add("@room", SqlDbType.VarChar).Value = room1.Text;
            cmd.Parameters.Add("@grower", SqlDbType.VarChar).Value = grower1.Text;
            cmd.Parameters.Add("@bins", SqlDbType.Int).Value = Convert.ToInt32(bins1.Text);
            cmd.Parameters.Add("@pack_as", SqlDbType.VarChar).Value = packas1.Text;
            cmd.Parameters.Add("@block", SqlDbType.VarChar).Value = block1.Text;
            cmd.Parameters.Add("@pool", SqlDbType.VarChar).Value = pool1.Text;

            cmd.CommandType = CommandType.Text;
            cmd.Connection = this.sqlConnection1;
            this.sqlConnection1.Open();
            // execute insert statement
            cmd.ExecuteNonQuery();
            this.sqlConnection1.Close();

            fill_grid();<-- fills other grid that shows the result of the insert
            fill_bins_grid();<-- fills this grid
            //Reset the edit index.
            grd_add_bins.EditIndex = -1;
            //Bind data to the GridView control.
            grd_add_bins.DataBind();



        }
4

1 回答 1

0

您需要一个 OnSelectedIndexChanged 方法。

于 2012-11-06T21:41:09.000 回答