2017-04-08 3 views
0

안녕하세요 저는 값을 동적으로 생성 한 텍스트 상자를 가져 와서 데이터베이스에 저장할 수 없습니다. PLZ 도움이 그의는 생성이 코드 텍스트 상자에 만든 코드는하지만 입력 텍스트의 값이 동적으로 생성 된 텍스트 상자에서 값을 검색 할 때 PLZ 나에게 도움이 오류를asp.net에서 동적으로 생성 된 텍스트 상자에서 값을 가져 오는 방법

protected void btnAtt_Click(object sender, EventArgs e) 
    { 
     int DPLID = int.Parse(DPLCategory.Text); 
     var query = (from p in database.tbl_Attributes 
        where p.ProductTypeId_FK == DPLID 
        select new 
        { 
         p.Attribute_Id, 
         p.AttributeName, 
         p.ProductTypeId_FK, 

        }).ToArray(); 
     for (int i = 0; i < query.Count(); i++) 
     { 
      Label lblatt = new Label(); 
      lblatt.ID = query[i].AttributeName; 
      lblatt.Text = query[i].AttributeName + " : "; 
      lblatt.CssClass = "control-label"; 
      TextBox txtatt = new TextBox(); 
      txtatt.ID = "txtatt"+i; 
      txtatt.Attributes.Add("runat", "server"); 
      txtatt.Text = String.Empty; 
      txtatt.CssClass = "form-control input-sm"; 
      HtmlTextWriterTag.Br.ToString(); 
      Place1.Controls.Add(lblatt); 
      HtmlTextWriterTag.Br.ToString(); 
      Place1.Controls.Add(txtatt); 
      HtmlTextWriterTag.Br.ToString(); 
     } 
    } 




protected void lbtnSave_Click(object sender, EventArgs e) 
    { 
     int DPLID = int.Parse(DPLCategory.Text); 
     var query = (from p in database.tbl_Attributes 
        where p.ProductTypeId_FK == DPLID 
        select new 
        { 
         p.Attribute_Id, 
         p.AttributeName, 
         p.ProductTypeId_FK, 

        }).ToArray(); 


      int LastId = database.tbl_Products.Max(p => p.ProductId); 

      for (int i = 0; i < query.Count(); i++) 
      { 

       database.tbl_ProductValue.Add(new Models.tbl_ProductValue() 
        { 
         ProductId_FK = LastId, 
         AttributeID_FK = query[i].Attribute_Id, 
         ProductValue = ??, 
        }); 
        database.SaveChanges(); 

      } 


     } 

을 제공 텍스트 상자를 얻는 방법?

나는 한 동안 WebForms와 함께 일하지 않은하지만 당신은 다음과 같이 자신의 ID에 의해 컨트롤에 액세스 할 수 있습니다

답변

0

:

ProductValue = ((TextBox)FindControl("txtatt" + i)).Text; 
+0

하지 근무를하지만,이 코드를 사용하여 '노력 VAR control1Value =으로 Request.Form [ " txtatt "+ i];' –

관련 문제