|
-
Feb 15th, 2004, 04:10 PM
#1
Thread Starter
PowerPoster
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:
'All this is in the load event right now.
If Not Page.IsPostBack Then
ddlLookups.DataSource = SqlHelper.ExecuteReader(strCon, CommandType.Text, _
"select name from sysobjects " & _
"where xtype='U' AND name LIKE 'LU%' ORDER BY name")
ddlLookups.DataTextField = "name"
ddlLookups.DataValueField = "name"
ddlLookups.DataBind()
End If
Dim strCommand As String
Dim dsData As New DataSet
strCommand = "SELECT * FROM " & ddlLookups.SelectedValue
dsData = SqlHelper.ExecuteDataset(strCon, CommandType.Text, strCommand)
dgLookup.DataSource = dsData.Tables(0)
dgLookup.DataBind()
Dim txtBox As TextBox
For Each dc As DataColumn In dsData.Tables(0).Columns
txtBox = New TextBox
txtBox.ID = dc.ColumnName
phInsert.Controls.Add(New LiteralControl(dc.ColumnName & ": "))
phInsert.Controls.Add(txtBox)
phInsert.Controls.Add(New LiteralControl("<BR>"))
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|