Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 How to capture Dynamic Data

Author  Topic 

abacusdotcom
Posting Yak Master

133 Posts

Posted - 2006-01-17 : 02:51:24
Hi All,
I have problem in manipulation my data grid.
My problem started with with d length of data from datatable, if I bind the dataTable to datagrid, it will be longer than the viewport of the screen, so the user/client will need to scroll horizontally, in user can loss track of the other part of the datagrid. So am thinking of transposing the data grid, so that the user will b able to scroll vertically.

1. How can I transpose a datagrid (vertical scrolling)
2. I have a work around, i built a dynamic table to solved the problem, my troubles started capturing data from the controls....

**************************** Code sample *********************************
Private Sub BuildGrid()
Dim sb As StringBuilder = New StringBuilder("")
Dim bTable As DataTable = objDataset.Tables("Groups")
Dim cTable As New DataTable

Dim dc As DataColumn
Dim dr As DataRow
Dim col As Integer = bTable.Columns.Count
Dim row As Integer = bTable.Rows.Count
Dim str As String = String.Empty
Dim i As Integer = 0
Dim j As Integer = 0

If DatasetIsEmpty(objDataset, bTable) Then
sb.Append("<table border='1'>")
sb.Append("<tr>")
cTable = TransposeTable(bTable, row, col)
sb.Append("<td>Group/Info</td>")
For i = 1 To row 'dc In cTable.Columns row change to column
sb.Append("<td>")
sb.Append("Group " & i)
sb.Append("</td>")
Next
sb.Append("</tr>")

For i = 0 To col - 1 'Each dr In cTable.Rows
' j = 0
' i = 0
'str = String.Empty
sb.Append("<tr>")

sb.Append("<td>")
sb.Append(bTable.Rows(0).Table.Columns(i).ColumnName.ToString)
sb.Append("</td>")

For j = 0 To row - 1 'Each dc In cTable.Columns
' If i = 0 Then
'End If
sb.Append("<td>")
'sb.Append(cTable.Rows(i).Item(j).ToString)

'sb.Append()
Select Case bTable.Rows(j).Table.Columns(i).DataType.ToString
Case "System.Boolean"
sb.Append("<input type='checkbox' name='chk" & j & i & "' value='checkbox' runat='server' />")
Case "System.Byte"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")
Case "System.Char"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.DateTime"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.Decimal"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.Decimal"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.Double"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.Int16"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.Int32"

sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")
Case "System.Int64"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.SByte"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.Single"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.UInt16"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.UInt32"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case "System.UInt64"
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' />")

Case Else
sb.Append("<input type='text' name='txt" & j & i & "' runat='server' value='" & bTable.Rows(j).Item(i).ToString & "' />")
End Select
sb.Append("</td>")

Next
sb.Append("</tr>")

Next

'for i = 1
sb.Append("</table>")
litShow.Text = sb.ToString
Else
Response.Write("Empty Record")
End If

End Sub

******************************** end of code ************************
These are d code i used in generating the dynamic table, i want to know how i can capture data dynamically from the table.

Thanks
abacus

I sign for fame not for shame but all the same, I sign my name.

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-17 : 08:16:25
abacus,

u "want to capture data" means what ?
Can't u have a for loop as follows ?

For j = 0 To row - 1
Capture [whatever u want to do] --> bTable.Rows(j).Table.Columns(i)
Next j

Or if ur concern is to get data from a database table and fill those in an HTML table, use recordset object of ADO
Go to Top of Page

abacusdotcom
Posting Yak Master

133 Posts

Posted - 2006-01-17 : 08:36:15
Hi,
Thanks Srinika, for your reply.

What I mean by capture data is to be able to get those data back from the generated controls back to the database.

>>Or if ur concern is to get data from a database table and fill those in an HTML table, use recordset object of ADO

I have already fill the html table with data, now i need to be able to capture the data back after edit to the database.

Thanks :)



I sign for fame not for shame but all the same, I sign my name.
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-01-17 : 12:12:59
You'll need to loop through the request.forms collection on the server side. You also may want to put something in the name of each control that tells you what it is and what "field" that it maps to.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>
Go to Top of Page

henrikop
Constraint Violating Yak Guru

280 Posts

Posted - 2006-01-28 : 03:37:52
You can make your own controls.

Public class SomeControls
Public Class DataBaseTextBox
Inherits TextBox
Private _SQLName As String
Property SQLName() As String
Get
Return _SQLName
End Get
Set(ByVal Value As String)
_SQLName = Value
End Set
End Property

So you add your controls dynamicaly (at Page.Init phase). By hitting a save button you loop through all the controls, read there SQLNames and construct a command...

There's a lot to it, but Google is your friend



Henri
~~~~
The envious praises me unknowingly
Go to Top of Page
   

- Advertisement -