Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i want to give a matrix as an input in my aspx file. I am using VB in my code behind page.The size of the matrix depends on the number , the user enters in a textbox. Suppose the user enters 4 in the text box. I should be able to open up 4 by 4 table of textboxes (or datagrid in edit mode probably) and ask the user to enter the values of the matrix in to those boxes and take that matrix of values and do my calculations. how should i create those textboxes dynamically?

I would appreciate if someone could help me out in this.

 

thanks

  • Moderators
Posted

Here's some code to create textboxes at runtime, I'm sure you can figure out the logic for the matrix.

       Dim txt As TextBox
       Dim x As Integer
       For x = 1 To Int16.Parse(TextBox1.Text)'textbox1 on form
           txt = New TextBox()
           With txt
               AddHandler .TextChanged, AddressOf txt_TextChanged
               .Text = ""
           End With
           Panel1.Controls.Add(txt)'Panel on form
       Next

Visit...Bassic Software
Posted

thank you very much for the help.

I have one more question.

I am trying to assign the width and height of the text boxes i generated using .width and .height properties. but i am getting an error saying

BC30311: Value of type 'Integer' cannot be converted to 'System.Web.UI.WebControls.Unit'

How should i assign the width.

 

thanks

  • 5 months later...
Posted

maintaining values of the dynamically created textboxes

 

few months back i had to stop working on this problem for some reasons......now this problem is back for me

 

as u said Robby i have created the text boxes.........now i am having problem with getting the values in the textboxes into an array.....

 

this is my code

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

Dim x As Integer

Dim y As Integer

 

Dim txt As TextBox

 

For x = 1 To System.Int16.Parse(boxes.Text)

 

Dim mybrl As New System.Web.UI.WebControls.Literal()

Panel1.Controls.Add(mybrl)

mybrl.Text = "<br/>"

 

For y = 1 To System.Int16.Parse(boxes.Text)

 

txt = New System.Web.UI.WebControls.TextBox()

 

txt.Text = ""

 

txt.ID = "T" + x.ToString() + y.ToString()

txt.Width = System.Web.UI.WebControls.Unit.Pixel(25)

 

Panel1.Controls.Add(txt)

 

Next

Next

End Sub

 

the boxes are created when i click the button "store" the following is called

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

 

Dim x As Integer

Dim y As Integer

Dim txtbox As TextBox

Dim mdata As Double(,)

 

mdata = New Double(System.Int16.Parse(boxes.Text) - 1, System.Int16.Parse(boxes.Text) - 1) {}

 

For x = 1 To mdata.Length

 

For y = 1 To mdata.Length

txtbox.ID = "T" + x.ToString() + y.ToString()

mdata(x - 1, y - 1) = txtbox.Text

Next

Next

 

End Sub

 

I am unable to maintain state for these textboxes......i have read that we need to use viewstate , recreate the textboxes etc. to do this......but i am totally confused how to implement in my program.....can anyone help me write this code.....

 

thanx

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...