Results 1 to 3 of 3

Thread: Dynamic DataGrid Question, having a dynamic insert row.

Threaded View

  1. #1

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Dynamic DataGrid Question, having a dynamic insert row.

    I am trying to create some maintenance type pages for the latest web application we are building. We have Look Up tables in our database and they are named with 'LU' in the beginning of the names. So, if we had a look up table that was a list of states, it would maybe have the name of LUStates. This allows us to easily find the purpose of the tables, and allows us to do things programatically against the names.

    I want to create one page for all lookup tables to allow maintenance to be done. Here is what I have now:
    VB Code:
    1. 'All this is in the load event right now.
    2.         If Not Page.IsPostBack Then
    3.             ddlLookups.DataSource = SqlHelper.ExecuteReader(strCon, CommandType.Text, _
    4.              "select name from sysobjects " & _
    5.              "where xtype='U' AND name LIKE 'LU%' ORDER BY name")
    6.             ddlLookups.DataTextField = "name"
    7.             ddlLookups.DataValueField = "name"
    8.             ddlLookups.DataBind()
    9.         End If
    10.  
    11.         Dim strCommand As String
    12.         Dim dsData As New DataSet
    13.         strCommand = "SELECT * FROM " & ddlLookups.SelectedValue
    14.         dsData = SqlHelper.ExecuteDataset(strCon, CommandType.Text, strCommand)
    15.         dgLookup.DataSource = dsData.Tables(0)
    16.         dgLookup.DataBind()
    17.  
    18.         Dim txtBox As TextBox
    19.         For Each dc As DataColumn In dsData.Tables(0).Columns
    20.  
    21.             txtBox = New TextBox
    22.             txtBox.ID = dc.ColumnName
    23.             phInsert.Controls.Add(New LiteralControl(dc.ColumnName & ": "))
    24.             phInsert.Controls.Add(txtBox)
    25.             phInsert.Controls.Add(New LiteralControl("<BR>"))
    26.         Next

    That code above loads a combo box with the list of tables, and depending on which is selected, displays the columns and rows in a datagrid that has the columns auto generated. This works well, I don't need anything fancy. My problem lies in the fact that I want to make a insertion row for that table. Not all tables have the same structure. Some have only two columns, others have 5. As you can see, I have accounted for that by dynamically adding textboxes to the form. I haven't went any further than this, only because I realize that I have some stuff I haven't accounted for....like a Identity Column. I don't want to show a textbox for that column. Also, what if a lookup table contains a column to another lookup. It would be nice to be able to show it as a drop down list instead of a textbox.

    Any ideas?

    It seems that I might need to hold a meta data type of table describing each look up table that I can query so I can dynamically change the controls....or possibly this information can be pulled from the system tables in the database. Just not sure about the route to take on this. I may be thinking all wrong, and someone has already solved this problem in a different way...who knows.
    Last edited by hellswraith; Feb 15th, 2004 at 05:31 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width