문제

FormView Control이 있습니다 ItemCreated 이벤트, 나는 기본값을 가진 일부 필드를 "프라이밍"하고 있습니다.

그러나 formview를 사용하여 삽입하기 전에 ItemInserting 어떤 이유로 든 이벤트가 호출됩니다 ItemCreated 첫 번째. 그 결과 삽입이 발생하기 직전에 필드가 기본값으로 과도하게 작성됩니다.

전화하지 않도록하려면 어떻게해야합니까? ItemCreated 전 이벤트 ItemInserting 이벤트?

도움이 되었습니까?

해결책

FormView Itemcreated 이벤트 대신 FormView 데이터 라운드 이벤트를 사용하여 값을 설정하고 :

protected void frm_DataBound(object sender, EventArgs e)
{
    if (frm.CurrentMode == FormViewMode.Edit)//whatever your mode here is.
    {
        TextBox txtYourTextBox = (TextBox)frm.FindControl("txtYourTextBox");
        txtYourTextBox.Text// you can set here your Default value
    }
}

또한 Similare 문제의 스레드를 확인하십시오c# asp.net을 덮어 쓰는 formview_load

다른 팁

이벤트가 발사되는 순서를 변경할 수 없습니다. 그러나 기본값을 내부에 설정하는 코드를 랩핑해야 할 것입니다. !IsPostBack 예를 들어 값을 재설정하지 않도록하십시오.

protected void FormView_ItemCreated(Object sender, EventArgs e)
{
  if(!IsPostBack)
  {
    //Set default values ...
  }
}

확인해보십시오 CurrentMode 양식보기의 속성.

void FormView_ItemCreated(object sender, EventArgs e)
{
    if (FormView.CurrentMode != FormViewMode.Insert)
    {
        //Initialize your default values here
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top