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 1 3347
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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),...
|
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,...
|
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...
| |
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...
|
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. ...
|
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...
|
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...
|
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,...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |