Databinding to a lookup table in an edititemtemplate class

B

Big Dave

Good morning. This group has been a great help so far, and it is much
appreciated. Here's my new question.

I want to be able to create a datagrid at runtime, which will have
template columns for editing. I have a table called company that has
a field called business model id. That id is a foreign key to the
business model lookup table. I've created a strongly typed dataset
for company that includes the business model lookup. I bind the
company table within the company dataset to the datagrid, and I've
created two template classes, one for the itemtemplate and one for the
edititemtemplate. Examples of the templates will be posted below.

Here's the problem, what is the best way, within the template, to get
the text value of the lookup table to display in the item template?
Should I pass the full dataset into the template and look it up that
way? Just pass the datatable? Should I just pass in the value of
what the textbox should be (I don't think this would work, but I'm not
sure)?

Here's what I'd like to happen, if it were my own programming
language, but I'm not sure how to accomplish it: I've got a reference
to the datarow, is there a way to "follow the relationship" within the
typed dataset to get to the text value in the lookup? I've seen some
stuff about GetChildRows, but all documentation I can find on it
refers to using it within a class or page where the dataset is. Is
that the way I should do it, and if so, how?

Thanks again for any help!!!


Imports System.Data.SqlClient

Public Class BusModelEditColumnTemplate
Implements ITemplate
Private _context As HttpContext
Public Sub New()
Me._context = HttpContext.Current
End Sub

Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Implements System.Web.UI.ITemplate.InstantiateIn
Dim ddl As New DropDownList
Dim BusModelBO As New BusObjects.BusModelBO(Me._context)
Dim da As New SqlDataAdapter
da = BusModelBO.GetDataAdapter

Dim dt As New CompanyDS.bus_model_lkuDataTable
da.Fill(dt)

ddl.DataSource = dt
ddl.DataTextField = dt.bus_model_nameColumn.ToString
ddl.DataValueField = dt.bus_model_idColumn.ToString
ddl.DataBind()

container.Controls.Add(ddl)
End Sub
End Class

Public Class BusModelItemColumnTemplate
Implements ITemplate
Private _context As HttpContext
Public Sub New(ByVal dt As DataTable)
Me._context = HttpContext.Current
End Sub

Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Implements System.Web.UI.ITemplate.InstantiateIn
Dim lbl As New Literal
lbl.Text = "I don't know how to set the text value of this
field"

container.Controls.Add(lbl)
End Sub


End Class
 
G

Guest

Check out Dino Esposito's columns on msdn.microsoft.com. In one of them, he
talked about parent-child relationships in a DataSet and binding it to a
"hierarchical" DataGrid. If I can find the URL, I will post.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top