Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to pass a control textbox and list array as parameters

Posted on 2009-04-29
2
Medium Priority
?
696 Views
Last Modified: 2012-05-06
I have two methods one whihc will create the array of textboxes and labels and teh other whihch will insert values into the arrays of labels and textboxes.I need to know how to pass teh array as a parameter to the filldata methos.  Please advise ASAP.


I  public void createcontrols( string table_name)
    {
        
      .............
         Label[] lbls1 = new Label[count];
       TextBox[] text_bx = new TextBox[count];
 
        int i = 0;
        while(i<count)
        {
            lbls1[i] = new Label();
            this.Controls.Add(lbls1[i]);
            i++;
        }
      i = 0;
      while (i < count)
      {
          text_bx[i] = new TextBox();
          this.Controls.Add(text_bx[i]);
          i++;
      }
 
    }
 public void filldata()
    {
 
        int j = 0;
        foreach (DataRow row in ds_tablespecs.Tables[0].Rows)
        {   
            HtmlTableRow htr_rowlbl = new HtmlTableRow();
            HtmlTableCell htc_ctrllbl = new HtmlTableCell();
            lbls1[j].Text = row["COLUMN_NAME"].ToString();
            htc_ctrllbl.Controls.Add(lbls1[j]);
            htr_rowlbl.Cells.Add(htc_ctrllbl);
            labels.Controls.Add(htr_rowlbl);
            
           //switch (ctrltype)
           //{
           //    case "DATE": 
           //        break;
 
           //    case "NUMBER": Console.WriteLine("HELLO");
           //        break;
 
           //    default:
           //        Console.WriteLine("NONE OF THE OPTIONS");
           //        break;
           //}
 
                HtmlTableRow htr_rowctrl = new HtmlTableRow();
            HtmlTableCell htc_ctrlctrl = new HtmlTableCell();
           string ctrltype = row["DATA_TYPE"].ToString();
             //TextBox txt_bx = new TextBox();
            text_bx[j].Text=  row["DATA_TYPE"].ToString();
            htc_ctrlctrl.Controls.Add(text_bx[j]);
            htr_rowctrl.Cells.Add(htc_ctrlctrl);
            controls.Controls.Add(htr_rowctrl);
            string col_null = row["NULLABLE"].ToString();
            //if (col_null == "Y")
            //{
            //    RequiredFieldValidator rv = new RequiredFieldValidator();
            //    rv.ControlToValidate = "txt_bx";
            //    htc_ctrlctrl.Controls.Add(rv);
            //    htr_rowctrl.Cells.Add(htc_ctrlctrl);
            //    controls.Controls.Add(htr_rowctrl);
            //    rv.Enabled = true;
            //    rv.ErrorMessage = "PLEASE FILL TEH TEXT BOX";
 
            //}
            j++;
      }
     }

Open in new window

0
Comment
Question by:aspgeek
1 Comment
 
LVL 4

Accepted Solution

by:
cauos earned 2000 total points
ID: 24259339
all what you have to do is sending the name of the array in the call method; and reciving the parameters as any other object but add the [] to let the method know that you are passing array
I  public void createcontrols( string table_name)
    {
        
      .............
         Label[] lbls1 = new Label[count];
       TextBox[] text_bx = new TextBox[count];
 
        int i = 0;
        while(i<count)
        {
            lbls1[i] = new Label();
            this.Controls.Add(lbls1[i]);
            i++;
        }
      i = 0;
      while (i < count)
      {
          text_bx[i] = new TextBox();
          this.Controls.Add(text_bx[i]);
          i++;
      }
filldata(lbls1,text_bx)
 
    }
 public void filldata(Label [] lbls1, TextBox [] text_bx)
    {
 
        int j = 0;
        foreach (DataRow row in ds_tablespecs.Tables[0].Rows)
        {   
            HtmlTableRow htr_rowlbl = new HtmlTableRow();
            HtmlTableCell htc_ctrllbl = new HtmlTableCell();
            lbls1[j].Text = row["COLUMN_NAME"].ToString();
            htc_ctrllbl.Controls.Add(lbls1[j]);
            htr_rowlbl.Cells.Add(htc_ctrllbl);
            labels.Controls.Add(htr_rowlbl);
            
           //switch (ctrltype)
           //{
           //    case "DATE": 
           //        break;
 
           //    case "NUMBER": Console.WriteLine("HELLO");
           //        break;
 
           //    default:
           //        Console.WriteLine("NONE OF THE OPTIONS");
           //        break;
           //}
 
                HtmlTableRow htr_rowctrl = new HtmlTableRow();
            HtmlTableCell htc_ctrlctrl = new HtmlTableCell();
           string ctrltype = row["DATA_TYPE"].ToString();
             //TextBox txt_bx = new TextBox();
            text_bx[j].Text=  row["DATA_TYPE"].ToString();
            htc_ctrlctrl.Controls.Add(text_bx[j]);
            htr_rowctrl.Cells.Add(htc_ctrlctrl);
            controls.Controls.Add(htr_rowctrl);
            string col_null = row["NULLABLE"].ToString();
            //if (col_null == "Y")
            //{
            //    RequiredFieldValidator rv = new RequiredFieldValidator();
            //    rv.ControlToValidate = "txt_bx";
            //    htc_ctrlctrl.Controls.Add(rv);
            //    htr_rowctrl.Cells.Add(htc_ctrlctrl);
            //    controls.Controls.Add(htr_rowctrl);
            //    rv.Enabled = true;
            //    rv.ErrorMessage = "PLEASE FILL TEH TEXT BOX";
 
            //}
            j++;
      }
     }

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question