pothuri Posted November 22, 2003 Posted November 22, 2003 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 Quote
Moderators Robby Posted November 23, 2003 Moderators Posted November 23, 2003 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 Quote Visit...Bassic Software
pothuri Posted November 24, 2003 Author Posted November 24, 2003 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 Quote
Moderators Robby Posted November 24, 2003 Moderators Posted November 24, 2003 it should be something like this... .Width = units.pixel(25) Quote Visit...Bassic Software
pothuri Posted April 24, 2004 Author Posted April 24, 2004 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.