开发者

Creating Dynamic Tables in VB.Net

I am new in .Net and I had a question regarding creating dynamic tables.

I am creating a page that adds a new row to a table (First Name, Last Name, Address, etc...) when a user clicks on a button. I have been reading that every time you do a postback to a dynamic table you have to re-create the rows. That is what I am doing.

I have been testing this and about 40 rows have being added already, when I click to add a new row, it runs completely slower and I can only imagine how long it would take to add 100 rows. I am assuming that it is because re-creating the rows takes time.

My questions is there a better approach or another way to accomplish task?

'***Edits Here what im currently doing

This is my table and button control:

Code when button is clicked, which creates the dynamic table:

  Dim tblrow As TableRow
  Dim tblcell As TableCell
  Dim inputText As TextBox

  tblrow = New TableHeaderRow

  tblcell = New TableHeaderCell
  tblcell.Text = tableCount 'variable used to count rows in the table
  tblcell.HorizontalAlign = HorizontalAlign.Left
  tblrow.Cells.Add(tblcell)

  tblcell = New TableCell
  inputText = New TextBox
  inputText.ID = "txt_" & tableCount
  tblcell.Controls.Add(inputText)
  tblrow.Cells.Add(tblcell)

  table1.rows.add(tblrow)

Now from what I learned and tested so far, everytime I do a postback I have to rebuild this table in order to keep all of the contents I entered into the table.

The next question is why dont you add another row using jquery so that you don't have to do postbacks. I have tried this approach and it worked well UNTIL I needed to put the information entered into the table into 开发者_StackOverflowa database which required a postback. So I was back at my original problem.

Note, if there is a better way to approach this im all ears. Like I said before I am new to this language and im just trying to learn.


My suggestion for you will be to use the JqGrid it is a free open source jquery plugin but also available commercially. It is fast in data loading and have lots of dynamic features

If you know javascript and jquery then this will be easy for you to use, it comes as Asp.Net, mvc and php component


Are you using windows forms? If you are, use the ListView control and change the view (I believe thats what it's called...) to details. Then you can use one of the many tutorials like this to populate the list:

If not using Windows Forums sorry, I saw the VB.net part and assumed.


asp.net is a server side web technology which means that you are working with a stateless technology (basically). That is why you have to rebuild everything on every postback.

There are several ways of dealing with this:

  • using the asp.net ViewState and check for Page.IsPostback on PageLoad
  • using jQuery and clientside Templates like Pure and fetch the Data through webservices

I on your behalf would avoid creating a table manually like you showed above, but instead use templated controls and specify the behavior declaratively.

When you create a DataGrid for example and are using ViewState, you do not have to explicitly recreate the DataGrid, since asp.net is taking care of it when used correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜