Populating a text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JonWB
    New Member
    • Feb 2008
    • 2

    Populating a text box

    Hi,

    I am very new to .Net and have recently taken over someone else’s project. I am developing an asp webpage using C#.

    I have an asp:table that is populated using data from a database. However, there is also a column that contains checkboxes and a column that contains text boxes like so:

    Location | Stock | Issue (checkbox column) | Issued (textbox column)

    I want the user to click a checkbox and the value of the ‘Stock’ column for that row is then entered into the textbox of that row.

    I have already populated the table with data and the user controls, I am only struggling with the event.

    My code is shown below:

    Code:
    TableRow row = new TableRow();
                    TableCell cellLoc = new TableCell();
                    TableCell cellStock = new TableCell();
                    TableCell cellIss = new TableCell();
                    TableCell cellIssued = new TableCell();
    
                    cellLoc.Width = Unit.Pixel(75);
                    cellStock.Width = Unit.Pixel(75);
                    cellIss.Width = Unit.Pixel(75);
                    cellIssued.Width = Unit.Pixel(75);
    
                    TextBox txtIssued = new TextBox();
                    CheckBox issue = new CheckBox();
                    
                    cellLoc.HorizontalAlign = HorizontalAlign.Left;
                    cellLoc.Text = location.Aisle + " " + location.Bay + " " + location.Level;
    
                    if (matReq.Status >= MaterialRequisitionStatus.Picking)
                    {
                        cellStock.Text = location.QtyRequired.ToString();
    
                        if (matReq.Status == MaterialRequisitionStatus.Picking)
                        {
                            if (userCanUpdate_)
                            {
                                issue.ID = "cbIssue_" + location.ProductCode + "_" + n.ToString();
                                string box = issue.ID;
                                issue.AutoPostBack = true;
                                cellIss.Controls.Add(issue);
                                txtIssued.Width = Unit.Pixel(50);
                                txtIssued.ID = "txtIssued_" + location.ProductCode + "_" + n.ToString();
                                txtIssued.Style.Add("text-align", "right");
                                cellIssued.Controls.Add(txtIssued);
    
                            }
                            else
                                cellIssued.Text = "-";
                        }
                        else
                            cellIssued.Text = location.QtyPicked.ToString();
                    }
                    else
                    {
                        cellStock.Text = location.Stock.ToString();
                        cellIssued.Text = "-";
                    }
    
                    row.Cells.Add(cellLoc);
                    row.Cells.Add(cellStock);
                    row.Cells.Add(cellIss);
                    row.Cells.Add(cellIssued);
    
                    tblStock.Rows.Add(row);
    This is my first post, so I hope I have given enough information for you to understand what I am attempting to do.

    Thanks in advance,

    Jonathan.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Have you tried the OnCheckedChange d event?

    Comment

    • JonWB
      New Member
      • Feb 2008
      • 2

      #3
      Thank you for your reply. I have tried OnCheckedChange d event with no success. I have been trying to use both the AutoPostBack and javascript in the following ways

      if (matReq.Status == MaterialRequisi tionStatus.Pick ing)
      {
      if (userCanUpdate_ )
      {
      issue.ID = "cbIssue_" + location.Produc tCode + "_" + n.ToString();
      string box = issue.ID;
      issue.AutoPostB ack = true;
      cellIss.Control s.Add(issue);
      txtIssued.Width = Unit.Pixel(50);
      txtIssued.ID = "txtIssued_ " + location.Produc tCode + "_" + n.ToString();
      txtIssued.Style .Add("text-align", "right");
      cellIssued.Cont rols.Add(txtIss ued);
      if (issue.Checked == false)
      txtIssued.Text = cellStock.Text;
      }
      else
      cellIssued.Text = "-";
      }

      and using javascript I replaced the if (issue.Checked == false) statement with:

      issue.Attribute s.Add("OnChecke dChanged", issue.ClientID + "javascript:_po pbox(cbIssue_" + location.Produc tCode + "_" + n.ToString() + ", txtIssued_" + location.Produc tCode + "_" + n.ToString() + ", " + cellStock.Text + ");");

      with javascript:

      function _popbox(check, txt, val)
      {
      if (check.checked = true)
      {
      txt.Text = val;
      }
      }

      I haven’t been able to get either method to work. Do you think that either of these ways are possible?

      Thanks,

      Jonathan.

      Comment

      Working...