Groups | Blog | Home
all groups > asp.net datagrid control > july 2004 >

asp.net datagrid control : Databind an embedded control in an embedded datagrid



Thomas Dodds
7/26/2004 4:20:58 PM
All,

I have something like the following:

Datagrid1
Col1 - bound column
Col2 - template column

Datagrid1_OnItemDataBound
datagrid2 - create new datagrid
col1 - template column
create new label
.text - need to bind data
.tooltip - need to bind data

I can display the data from the existing dataset using a dataview and
rowfilter and setting the DataField property (if I use a boundcolumn instead
of the templatecolumn)

What I am missing is the expression to bind the data to specific properties
of the label control. Typically I would use Databinder.Eval(Container,
"DataItem.FIELDNAME"), but I have no Container (I understand this must be
the DatagridItem (Row) object) as it doesn't exist yet. What are my
options? I will forward my Datagrid1_OnItemDataBound sub to anyone via
email should you want to see it.

Thanks,

Thomas

Jared
7/29/2004 5:15:42 AM
Thomas,
You could try to set the data source of the bound grid to a custom
function, mabye pass in some values that will help narrow the selection.
Then you can use the DataBinder.Eval function in your child grid. You may
have to save your original data in viewstate to keep it from re-binding over
and over. I think the visual basic resource kit has some examples.
Hope this helps,
Jared

ex.
'Child DataGrid's databinding
DataSource='<%# MyCustomFunction(DataBinder.Eval(Container.DataItem,
"SomeIndexedValue")) %>'

'Codebehind
Protected Function MyCustomFunction(ByVal SomeIndexedValue As String) As
DataSet
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString =
"Server=MyServer;Database=MyDataBase;Trusted_Connection=True;"
conn.Open()
Dim da As New SqlClient.SqlDataAdapter("SELECT * FROM MyTable WHERE
(MyIndexedField='" & SomeIndexedValue & "')", conn)
Dim ds As New DataSet
da.Fill(ds)
conn.Close()
Return ds
End Function

[quoted text, click to view]

AddThis Social Bookmark Button