473,806 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding to a lookup table in an edititemtemplat e class

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
edititemtemplat e. 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.Sql Client

Public Class BusModelEditCol umnTemplate
Implements ITemplate
Private _context As HttpContext
Public Sub New()
Me._context = HttpContext.Cur rent
End Sub

Public Sub InstantiateIn(B yVal container As System.Web.UI.C ontrol)
Implements System.Web.UI.I Template.Instan tiateIn
Dim ddl As New DropDownList
Dim BusModelBO As New BusObjects.BusM odelBO(Me._cont ext)
Dim da As New SqlDataAdapter
da = BusModelBO.GetD ataAdapter

Dim dt As New CompanyDS.bus_m odel_lkuDataTab le
da.Fill(dt)

ddl.DataSource = dt
ddl.DataTextFie ld = dt.bus_model_na meColumn.ToStri ng
ddl.DataValueFi eld = dt.bus_model_id Column.ToString
ddl.DataBind()

container.Contr ols.Add(ddl)
End Sub
End Class

Public Class BusModelItemCol umnTemplate
Implements ITemplate
Private _context As HttpContext
Public Sub New(ByVal dt As DataTable)
Me._context = HttpContext.Cur rent
End Sub

Public Sub InstantiateIn(B yVal container As System.Web.UI.C ontrol)
Implements System.Web.UI.I Template.Instan tiateIn
Dim lbl As New Literal
lbl.Text = "I don't know how to set the text value of this
field"

container.Contr ols.Add(lbl)
End Sub
End Class
Nov 18 '05 #1
1 3364
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
"hierarchic al" 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
edititemtemplat e. 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.Sql Client

Public Class BusModelEditCol umnTemplate
Implements ITemplate
Private _context As HttpContext
Public Sub New()
Me._context = HttpContext.Cur rent
End Sub

Public Sub InstantiateIn(B yVal container As System.Web.UI.C ontrol)
Implements System.Web.UI.I Template.Instan tiateIn
Dim ddl As New DropDownList
Dim BusModelBO As New BusObjects.BusM odelBO(Me._cont ext)
Dim da As New SqlDataAdapter
da = BusModelBO.GetD ataAdapter

Dim dt As New CompanyDS.bus_m odel_lkuDataTab le
da.Fill(dt)

ddl.DataSource = dt
ddl.DataTextFie ld = dt.bus_model_na meColumn.ToStri ng
ddl.DataValueFi eld = dt.bus_model_id Column.ToString
ddl.DataBind()

container.Contr ols.Add(ddl)
End Sub
End Class

Public Class BusModelItemCol umnTemplate
Implements ITemplate
Private _context As HttpContext
Public Sub New(ByVal dt As DataTable)
Me._context = HttpContext.Cur rent
End Sub

Public Sub InstantiateIn(B yVal container As System.Web.UI.C ontrol)
Implements System.Web.UI.I Template.Instan tiateIn
Dim lbl As New Literal
lbl.Text = "I don't know how to set the text value of this
field"

container.Contr ols.Add(lbl)
End Sub
End Class

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
911
by: hasden | last post by:
I want to remotely load an edititemtemplate into a formview control. I am currently loading the item templates from .ascx files just fine and they run the <%# Eval() #> stuff and everything is perfect. The problem comes when I try to move the working edititemtemplate out of the aspx file and into an aspx for various reasons. Once the edititemtemplate is in an ascx file, it seems as though the <%# Bind() #> methods no longer work correctly....
4
2586
by: Vik | last post by:
How can I display the lookup values in a datagrid? E.g., the datagrid displays a table that contains a ProductID field. I want to display a Product description from a Product table in that datagrid. Currently I use a join between the main table and the lookup table to get the Product description. Is it possible to use a dropdownlist in the datagrid to display and select (in Edit mode) the lookup values? Thank you.
4
4214
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox), SqlConnection (sqlConnection), SqlDataAdapter (daLookupData), SqlDataAdapter (daData), DataSet (dsLookupData), and DataSet (dsData), all created via the IDE during design-time. Here is the design of my simple tables: (An example since I can't post my...
3
3165
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method, depending on which menu item a user selects. Each of these controls follows the same basic pattern: Get a dataset from the database and then display the results using basic databinding. Everything works fine except that I'll occaisionally get an...
1
2821
by: dieter | last post by:
Two-way databinding (as described in http://dotnetjunkies.com/QuickStartv20/aspnet/doc/data/templates.aspx) works fine for me if I use it within aspx-files. However, I would like to use it my codehind file and I don't know how to get it work since I did not find any equivalent for "Bind" to use in my ITemplate derived class. For my ItemTemplate, I use (int)((DataRowView)container.DataItem) as equivalent to <%# Eval ...%>
6
2089
by: Douglas J. Badin | last post by:
Earlier this month, there was a posting about this without a definitive answer. If you place a Wizard inside a FormView's EditItemTemplate the bound fields contained within the View will display the data from the fields to which they are bound; yet they will return null values when the 'Update' LinkButton is clicked. The responder thought this might have something to do with naming containers. If so, this is similar to an issue in...
1
14318
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. Both the grid and the dropdown box are retrieving and displaying data fine, I just cant bind the two together. I followed the instructions in the help document called 'Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web...
2
2546
by: bpd | last post by:
I have a user control embedded in a gridview as an EditItemTemplate. When updating, the value is not saved to the database. I have an SQLDataSource attached to the Gridview. Can someone point me to a good example or discussion about the two way databinding. I use C#. thanks
2
1359
by: David C | last post by:
I have a drop down list control where I set AppendDataBound to true and added a list item of '<< add new>>' with a value of -1 to use for adding items to the list during data entry. When the user selects the '<< add new The new name is stored in a hidden TextBox and in the Load event I use it to add the record to the lookup table. Below is the block of code in the Load event of the FormView. Dim row As FormViewRow = fvTrademark.Row...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.