D
David P. Donahue
Currently, when I bind data to a DataGrid, I use a function as such:
Dim conGrid As SqlClient.SqlConnection
Dim daGrid As SqlClient.SqlDataAdapter
Dim dsGrid As DataSet
Dim stringSQL As String
stringSQL = "SELECT * FROM UserProfiles"
conGrid = New SqlClient.SqlConnection(Global.strDBConnect)
daGrid = New SqlClient.SqlDataAdapter(stringSQL, conGrid)
dsGrid = New DataSet
daGrid.Fill(dsGrid)
DataGrid1.DataSource = dsGrid
DataGrid1.DataBind()
Then, in the DataGrid's Template Columns, controls would have something
like:
text='<%# DataBinder.Eval(Container.DataItem, "Username") %>'
For various reasons, I would like to not have this piece of code in the
..aspx file, but would prefer to have all my VB code running in the
..aspx.vb (code-behind) file. How would I accomplish setting this text
property in this way in my code-behind from the function above? In my
code for handling DataGrid commands (update, for example), I have things
like:
Dim textBoxDay As TextBox
Dim stringDay As String
textBoxDay = e.Item.Cells(3).Controls(1)
stringDay = textBoxDay.Text
Here, "e" is of type DataGridCommandEventArgs and is passed to the
DataGrid1_UpdateCommand function by design. Its "Item" collection is
great for referencing controls in the Template Columns. But, how would
I reference them in the earlier mentioned code?
Regards,
David P. Donahue
(e-mail address removed)
Dim conGrid As SqlClient.SqlConnection
Dim daGrid As SqlClient.SqlDataAdapter
Dim dsGrid As DataSet
Dim stringSQL As String
stringSQL = "SELECT * FROM UserProfiles"
conGrid = New SqlClient.SqlConnection(Global.strDBConnect)
daGrid = New SqlClient.SqlDataAdapter(stringSQL, conGrid)
dsGrid = New DataSet
daGrid.Fill(dsGrid)
DataGrid1.DataSource = dsGrid
DataGrid1.DataBind()
Then, in the DataGrid's Template Columns, controls would have something
like:
text='<%# DataBinder.Eval(Container.DataItem, "Username") %>'
For various reasons, I would like to not have this piece of code in the
..aspx file, but would prefer to have all my VB code running in the
..aspx.vb (code-behind) file. How would I accomplish setting this text
property in this way in my code-behind from the function above? In my
code for handling DataGrid commands (update, for example), I have things
like:
Dim textBoxDay As TextBox
Dim stringDay As String
textBoxDay = e.Item.Cells(3).Controls(1)
stringDay = textBoxDay.Text
Here, "e" is of type DataGridCommandEventArgs and is passed to the
DataGrid1_UpdateCommand function by design. Its "Item" collection is
great for referencing controls in the Template Columns. But, how would
I reference them in the earlier mentioned code?
Regards,
David P. Donahue
(e-mail address removed)