Databinding to a lookup table in an edititemtemplate class

Discussion in 'ASP .Net' started by Big Dave, Oct 7, 2004.

  1. Big Dave

    Big Dave Guest

    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
     
    Big Dave, Oct 7, 2004
    #1
    1. Advertising

  2. 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
    >
     
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, Oct 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    1
    Views:
    3,191
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Dec 1, 2005
  2. E11
    Replies:
    1
    Views:
    4,950
    Thomas Weidenfeller
    Oct 12, 2005
  3. jobs
    Replies:
    0
    Views:
    1,775
  4. Adam
    Replies:
    2
    Views:
    451
    dontlikenicknames
    Sep 2, 2008
  5. Earl Teigrob
    Replies:
    1
    Views:
    446
    Shravan
    Mar 1, 2004
Loading...

Share This Page