2012-10-18 7 views
3

버튼으로 채워진 괄호로 테이블을 만듭니다. 버튼은 "Update"라고 불리며 클릭하면 모든 것이 잘 동작합니다. 이 표 아래에는 변경 사항의 기록을 볼 수있는 "로그"버튼이 있습니다. 첫 번째 테이블 (테이블이있는 패널)을 숨기고 두 번째 테이블을 표시하여 두 번째 테이블을 표시합니다. 이 테이블에는 상태가 0 인 데이터를 복원하는 "복원"버튼이있는 열이 있습니다. 내 문제는 여기 있습니다.이 버튼을 클릭하면 페이지의 requiredfieldvalidators가 트리거됩니다. Validationgroup과 Causesvalidation을 사용했지만 아무 것도 작동하지 않는 것 같습니다. 제발 도와주세요! 업데이트 BTN와버튼과 requirefieldvalidator가있는 동적으로 생성 된 테이블 C#

표 잘 작동 : BTN을 복원와

public void setUpdate(object sender, EventArgs e) 
{ 
    Button btn = (Button)sender; 
    string id = btn.ID; 
    int idInt = Convert.ToInt32(id.Substring(6)); 

    Provider p = new Provider(); 
    Address a = new Address(); 

    p = (Provider)providers[idInt - 1]; 
    a.setAddressID(p.getAddressID()); 
    a = a.getAddressByID(); 

    pUpdate.Visible = true; 

    lbl_providerID.Text = p.getProviderID().ToString(); 
    txt_pUpdate_Name.Text = p.getName(); 
    txt_pUpdate_Phone.Text = p.getPhone(); 
    txt_pUpdate_Street.Text = a.getStreet(); 
    txt_pUpdate_Number.Text = a.getNumber().ToString(); 
    txt_pUpdate_City.Text = a.getCity(); 
    txt_pUpdate_ZipCode.Text = a.getZipCode(); 
    txt_pUpdate_Country.Text = a.getCountry(); 
} 

두 번째 테이블 : 업데이트 BTN의

public void getData() 
{ 
    Provider p = new Provider(); 
    providers = p.getAllProviders(); 
    int count = 1; 

    //Create a Table 
    Table tbl = new Table(); 
    tbl.Style["Border-width"] = "5px"; 
    tbl.Style["Border-style"] = "solid"; 
    tbl.GridLines = GridLines.Both; 
    tbl.CellPadding = 5; 

    //Header of Table 
    TableRow infoRow = new TableRow(); 

    //Cell of header 
    TableCell tch0 = new TableCell(); 
    tch0.Text = "<b>ProviderID</b>"; 
    TableCell tch1 = new TableCell(); 
    tch1.Text = "<b>Name</b>"; 
    TableCell tch2 = new TableCell(); 
    tch2.Text = "<b>Phone</b>"; 
    TableCell tch3 = new TableCell(); 
    tch3.Text = "<b>Address</b>"; 
    TableCell tch4 = new TableCell(); 
    tch4.Text = "<b>Update</b>"; 

    //Add cells to header 
    infoRow.Cells.Add(tch0); 
    infoRow.Cells.Add(tch1); 
    infoRow.Cells.Add(tch2); 
    infoRow.Cells.Add(tch3); 
    infoRow.Cells.Add(tch4); 

    //Add header to table 
    tbl.Rows.Add(infoRow); 

    if (providers != null) 
    { 
     foreach (Provider pr in providers) 
     { 
      //Create a row 
      TableRow tr = new TableRow(); 

      //Add lable to evry cell 
      TableCell tc1 = new TableCell(); 
      Label pID = new Label(); 
      tc1.Controls.Add(pID); 

      TableCell tc2 = new TableCell(); 
      Label name = new Label(); 
      tc2.Controls.Add(name); 

      TableCell tc3 = new TableCell(); 
      Label phone = new Label(); 
      tc3.Controls.Add(phone); 

      TableCell tc4 = new TableCell(); 
      Label address = new Label(); 
      tc4.Controls.Add(address); 

      TableCell tc5 = new TableCell(); 
      Button updateBtn = new Button(); 
      updateBtn.Click += new System.EventHandler(setUpdate); 
      updateBtn.Text = "Update"; 
      updateBtn.ID = "update" + count; 
      updateBtn.ValidationGroup = "updateGrp"; 
      tc5.Controls.Add(updateBtn); 

      //Fill lables 
      pID.Text = pr.getProviderID().ToString(); 
      name.Text = pr.getName(); 
      phone.Text = pr.getPhone(); 

      Address a = new Address(); 
      a.setAddressID(pr.getAddressID()); 
      a = a.getAddressByID(); 
      address.Text = a.getStreet() + " " + a.getNumber() + " " + a.getCity() + " " + a.getZipCode() + " " + a.getCountry(); 

      //Add cells to row 
      tr.Cells.Add(tc1); 
      tr.Cells.Add(tc2); 
      tr.Cells.Add(tc3); 
      tr.Cells.Add(tc4); 
      tr.Cells.Add(tc5); 

      //Add row to table 
      tbl.Rows.Add(tr); 
      count++; 
     } 
    } 
    //Add table to form 
    pTableData.Controls.Add(tbl); 
} 

기능

: 여기

는 일부 코드입니다
public void getLog() 
{ 
    LogProvider lp = new LogProvider(); 
    logproviders = lp.getAllLogProviders(); 
    int count = 1; 

    //Create a Table 
    Table tbl = new Table(); 
    tbl.Style["Border-width"] = "5px"; 
    tbl.Style["Border-style"] = "solid"; 
    tbl.GridLines = GridLines.Both; 
    tbl.CellPadding = 5; 

    //Header of Table 
    TableRow infoRow = new TableRow(); 

    //Cell of header 
    TableCell tch0 = new TableCell(); 
    tch0.Text = "<b>LogProviderID</b>"; 
    TableCell tch1 = new TableCell(); 
    tch1.Text = "<b>Name</b>"; 
    TableCell tch2 = new TableCell(); 
    tch2.Text = "<b>Phone</b>"; 
    TableCell tch3 = new TableCell(); 
    tch3.Text = "<b>Address</b>"; 
    TableCell tch4 = new TableCell(); 
    tch4.Text = "<b>Status</b>"; 
    TableCell tch5 = new TableCell(); 
    tch5.Text = "<b>Type</b>"; 
    TableCell tch6 = new TableCell(); 
    tch6.Text = "<b>Updated on</b>"; 
    TableCell tch7 = new TableCell(); 
    tch7.Text = "<b>Changed by</b>"; 
    TableCell tch8 = new TableCell(); 
    tch8.Text = "<b>Restore</b>"; 

    //Add cells to header 
    //infoRow.Cells.Add(tch0); 
    infoRow.Cells.Add(tch1); 
    infoRow.Cells.Add(tch2); 
    infoRow.Cells.Add(tch3); 
    infoRow.Cells.Add(tch4); 
    infoRow.Cells.Add(tch5); 
    infoRow.Cells.Add(tch6); 
    infoRow.Cells.Add(tch7); 
    infoRow.Cells.Add(tch8); 

    //Add header to table 
    tbl.Rows.Add(infoRow); 

    if (providers != null) 
    { 
     foreach (LogProvider logp in logproviders) 
     { 
      //Create a row 
      TableRow tr = new TableRow(); 

      //Add lable to evry cell 
      TableCell tc1 = new TableCell(); 
      Label lpID = new Label(); 
      tc1.Controls.Add(lpID); 

      TableCell tc2 = new TableCell(); 
      Label name = new Label(); 
      tc2.Controls.Add(name); 

      TableCell tc3 = new TableCell(); 
      Label phone = new Label(); 
      tc3.Controls.Add(phone); 

      TableCell tc4 = new TableCell(); 
      Label address = new Label(); 
      tc4.Controls.Add(address); 

      TableCell tc5 = new TableCell(); 
      Label status = new Label(); 
      tc5.Controls.Add(status); 

      TableCell tc6 = new TableCell(); 
      Label type = new Label(); 
      tc6.Controls.Add(type); 

      TableCell tc7 = new TableCell(); 
      Label updatedOn = new Label(); 
      tc7.Controls.Add(updatedOn); 

      TableCell tc8 = new TableCell(); 
      Label by = new Label(); 
      tc8.Controls.Add(by); 

      TableCell tc9 = new TableCell(); 

      //Fill lables 
      lpID.Text = logp.getLogProviderID().ToString(); 
      name.Text = logp.getName(); 
      phone.Text = logp.getPhone(); 

      LogAddress la = new LogAddress(); 
      la.setLogAddressID(logp.getLogProviderID()); 
      la = la.getLogAddressByID(); 
      address.Text = la.getStreet() + " " + la.getNumber() + " " + la.getCity() + " " + la.getZipCode() + " " + la.getCountry(); 

      int stat; 
      if (logp.getStatus()) 
       stat = 1; 
      else 
       stat = 0; 

      status.Text = stat.ToString(); 
      type.Text = logp.getType(); 
      updatedOn.Text = String.Format("{0:yyyy-MM-dd HH:mm:ss}", logp.getUpdateDate()); 
      by.Text = logp.getUserName(); 

      if(stat == 0) 
      { 
       Button restoreBtn = new Button(); 
       restoreBtn.Click += new System.EventHandler(setRestore); 
       restoreBtn.Text = "Restore"; 
       restoreBtn.ID = "restore" + count; 
       restoreBtn.ValidationGroup = "restoreGrp"; 
       tc9.Controls.Add(restoreBtn); 
      } 

      //Add cells to row 
      //tr.Cells.Add(tc1); 
      tr.Cells.Add(tc2); 
      tr.Cells.Add(tc3); 
      tr.Cells.Add(tc4); 
      tr.Cells.Add(tc5); 
      tr.Cells.Add(tc6); 
      tr.Cells.Add(tc7); 
      tr.Cells.Add(tc8); 
      tr.Cells.Add(tc9); 

      //Add row to table 
      tbl.Rows.Add(tr); 
      count++; 
     } 
    } 
    //Add table to form 
    pTableLog.Controls.Add(tbl); 
} 

복원 BTN의 기능 (작동하지 않습니다!) :

public void setRestore(object sender, EventArgs e) 
{ 
    Button btn = (Button)sender; 
    string id = btn.ID; 
    int idInt = Convert.ToInt32(id.Substring(7)); 

    LogProvider lp = new LogProvider(); 
    Provider p = new Provider(); 
    LogAddress la = new LogAddress(); 

    lp = (LogProvider)logproviders[idInt - 1]; 
    p.setProviderID(lp.getProviderID()); 
    p = p.getProviderByID(); 
    la.setLogAddressID(lp.getProviderID()); 

} 

답변

0

페이지에서 필요한 필드 유효성 검사기 뒤에 논리에 대해 확실하지 않다. validators 이벤트가 발사되지 않기 때문에 내 understandinf 무엇입니까?

버튼 클릭 이벤트를 호출하고

+0

requirefieldvalidators 5 텍스트 상자에있는 나중에 활성화 직전 그래서 당신이 유효성 검사기를 해제 할 수 있습니다. 그들은 단지 필요한 값을 확인하기 위해 거기에 있습니다. 괜찮 으면 모든 값보다 db에 삽입됩니다. 따라서 requirefieldvalidators는 insert btn에만 있습니다. 복원을 클릭 할 때 트리거 할 필요는 없지만 그렇게하면됩니다. –

관련 문제