我在模板字段中有一个下拉列表,它在加载时将其选定值设置为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();
}
答案 0 :(得分:0)
您需要一个OnSelectedIndexChanged方法。