我目前正在使用listview来编辑和更新数据。当我点击编辑时,它会进入我想要的编辑格式。我希望能够在单击更新按钮后退出整个编辑模式。这可能吗?
当我使用ListView1.EditIndex = -1时,它不会返回到常规视图。
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
updateButton = true;
ListViewItem lvl = ListView1.Items[e.ItemIndex];
var formTitleListBox = (ListBox)lvl.FindControl("ListBox1");
var controlTypeListBox = (ListBox)lvl.FindControl("ControlType");
var formSectionListBox = (ListBox)lvl.FindControl("formsection");
var sortOrderTextBox = (TextBox)lvl.FindControl("SortOrderTextBox");
var subsectionListBox = (ListBox)lvl.FindControl("subsection");
var subSectionTextBox = (TextBox)lvl.FindControl("SubSectionOrderTextBox");
var sectionItemListBox = (ListBox)lvl.FindControl("sectionitem");
var sectionSortOrderTextBox = (TextBox)lvl.FindControl("SectionSortOrderTextBox");
var validationRuleListBox = (ListBox)lvl.FindControl("RuleDesc");
var crossItemListBox = (ListBox)lvl.FindControl("CrossItem");
var hiddenID = (HiddenField)lvl.FindControl("HiddenPrimaryID");
using (SqlConnection connection = new SqlConnection("Data Source=RCK-HRSA-DB01;Initial Catalog=ORHP_Dev03182014;User ID=ohitrural;Password=0h!trural"))
{
try
{
SqlCommand cmd1 = new SqlCommand("UPDATE ORHP_Dev03182014.Core.Form_Section_SubSection_Item_Rel SET FormID = @FormTitle, FormSectionID = @FormSection, SubSectionID = @SubSection, SectionItemID = @SectionItem, SortOrder = @SortOrder, SectionSortOrder = @SectionSortOrder, SubSectionSortOrder = @SubSectionSortOrder, ValidationRulesetId = @RuleDesc, ControlTypeID = @ControlType, CrossItemID = @CrossItem WHERE DataCollectionPeriodID = " + DropDownList2.SelectedValue + " AND FormSectionSubSectionItemRelID = @FormSectionSubSectionID");
connection.Open();
cmd1.Connection = connection;
cmd1.CommandType = CommandType.Text;
cmd1.Parameters.AddWithValue("@FormTitle", formTitleListBox.SelectedValue);
cmd1.Parameters.AddWithValue("@ControlType", DbNullIfNull(controlTypeListBox.SelectedValue));
cmd1.Parameters.AddWithValue("@FormSection", formSectionListBox.SelectedValue);
cmd1.Parameters.AddWithValue("@SortOrder", DbNullIfNull(sortOrderTextBox.Text));
cmd1.Parameters.AddWithValue("@SubSection", subsectionListBox.SelectedValue);
cmd1.Parameters.AddWithValue("@SubSectionSortOrder", DbNullIfNull(subSectionTextBox.Text));
cmd1.Parameters.AddWithValue("@SectionItem", sectionItemListBox.SelectedValue);
cmd1.Parameters.AddWithValue("@SectionSortOrder", DbNullIfNull(sectionSortOrderTextBox.Text));
cmd1.Parameters.AddWithValue("@RuleDesc", DbNullIfNull(validationRuleListBox.SelectedValue));
cmd1.Parameters.AddWithValue("@CrossItem", DbNullIfNull(crossItemListBox.SelectedValue));
cmd1.Parameters.AddWithValue("@FormSectionSubSectionID", hiddenID.Value);
cmd1.ExecuteNonQuery();
SqlDataAdapter dt = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
searchDS = new DataSet();
dt.Fill(ds);
searchDS = ds;
UpdatePanel1.Update();
ListView1.DataSource = searchDS;
ListView1.EditIndex = -1;
ListView1.DataBind();
e.Cancel = true;
}
catch (Exception ex)
{
}
}
}
答案 0 :(得分:1)
添加ListView1.DataBind();
和e.Cancel = true;
。
// ...
cmd1.ExecuteNonQuery();
ListView1.EditIndex = -1;
ListView1.DataBind()
e.Cancel = true;
// ...
旁注:如果您想要注意出现问题,请删除空捕获。