By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,018 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,018 IT Pros & Developers. It's quick & easy.

Databinding to a lookup table in an edititemtemplate class

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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!
***************************

"Big Dave" wrote:
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.