dynamically creating a check box in a datagrid

Discussion in 'ASP.NET / ASP.NET Core' started by villagecirc, Sep 28, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Below I am pasting the code in its entireity. I have created mulitiple datagrids with a check box template column dynamically by overiding the itemplate class. However when I try to access the check box It does not exist I think it is getting wiped on the post back I have tried to access the data grids by overiding the loadviewstate function to no avail. Has anyone worke with dynamic objects and capturing their data. If so please help....



    Imports CustomerShipmentsBussiness
    Public Class ShipmentDetail
    Inherits System.Web.UI.Page
    Protected WithEvents ucHeader1 As ucHeader

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblCustNo As System.Web.UI.WebControls.Label
    Protected WithEvents lblCustName As System.Web.UI.WebControls.Label
    Protected WithEvents dgCustomer As System.Web.UI.WebControls.DataGrid
    Protected WithEvents lblSort As System.Web.UI.WebControls.Label
    Protected WithEvents lblAsc As System.Web.UI.WebControls.Label
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents lblSalesOrder As System.Web.UI.WebControls.Label
    Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    Protected WithEvents pnlShip As System.Web.UI.WebControls.Panel
    Protected WithEvents btnUpdate As System.Web.UI.WebControls.Button
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Label4 As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not Page.IsPostBack Then

    lblCustNo.Text = Request.Params("CustNo")
    lblCustName.Text = Request.Params("CustName")
    lblSalesOrder.Text = Request.Params("SO")
    RetrieveShipmentDetail(lblSort.Text, lblAsc.Text)

    End If


    ucHeader1.Header = "Shipment Detail"
    ucHeader1.Header2 = lblCustName.Text
    ucHeader1.Header3 = lblCustNo.Text

    'update check boxes in case they were checked

    End Sub


    Public Sub RetrieveShipmentDetail(ByVal SortKey As String, ByVal Asc As String)
    Dim x, y, z As Integer
    x = 0 'use to track ShipNo
    y = 0 'use to track CartNo
    z = 1 'use to track datatable items
    Dim ShipNo(100) As String
    Dim CartNo(100, 10) As String
    Dim dt(100, 10) As DataTable
    Dim prevShipNo As String = ""
    Dim prevCartNo As String = ""
    Dim dr As DataRow
    Dim i As Integer
    Dim oAW As CustomerShipmentsBussiness.Shipments = New CustomerShipmentsBussiness.Shipments
    Dim ds As DataSet, dsMultiple As DataSet

    Dim sCartNo As String = ""
    Dim sShipNo As String = ""

    Try
    oAW.CustNo = lblCustNo.Text 'custno is passed in from login
    oAW.SalesOrder = lblSalesOrder.Text
    ds = oAW.GetShipments()

    Dim rowMbr As DataRow

    For Each rowMbr In ds.Tables("Shipments").Rows
    'capture customer name just fist time through
    If i = 0 Then
    lblCustName.Text = Trim(rowMbr("Customer"))
    End If

    'substitute rowmbr with variables to avoid null value errors
    If IsDBNull(rowMbr("DisplayShipNo")) Then
    sShipNo = ""
    Else
    sShipNo = Trim(rowMbr("DisplayShipNo"))
    End If
    If IsDBNull(rowMbr("DisplayCartTag")) Then
    sCartNo = ""
    Else
    sCartNo = Trim(rowMbr("DisplayCartTag"))
    End If

    If sShipNo <> prevShipNo Then 'New shipNO
    'check table if table exists create data grid for previous cartno
    If x > 0 Then 'if x is zero than no cart exists yet
    If dt(x, y).Rows.Count > 0 Then
    CreateDataGrid(x, y, dt(x, y))
    End If
    End If

    x += 1 'increment ShipNo count
    y = 0 'reset cart count
    ShipNo(x) = sShipNo 'build ShipNo string array
    prevShipNo = ShipNo(x) 'set prevShipNo to current value
    CreateLabel(x, ShipNo(x), Trim(rowMbr("ShipDate")), Trim(rowMbr("ShippedBy")), Trim(rowMbr("Driver")), Trim(rowMbr("Addr1")))
    If sCartNo <> prevCartNo Then 'New CartNo
    y += 1 'increment cart count

    CartNo(x, y) = sCartNo 'Build CartNo string array
    prevCartNo = CartNo(x, y)
    CreateLabel(x, y, CartNo(x, y))

    dt(x, y) = New DataTable 'start new table for every new cart

    dt(x, y).Columns.Add(New DataColumn("QtyCarted", GetType(String))) '3rd data level 0
    dt(x, y).Columns.Add(New DataColumn("Item", GetType(String))) '3rd data level 1
    dt(x, y).Columns.Add(New DataColumn("Lenght", GetType(String))) '3rd data level 2
    dt(x, y).Columns.Add(New DataColumn("Color", GetType(String))) '3rd data level 3
    dt(x, y).Columns.Add(New DataColumn("PkgType", GetType(String))) '3rd data level 4
    dt(x, y).Columns.Add(New DataColumn("DisplayShipNo", GetType(String))) '1st data level 5
    dt(x, y).Columns.Add(New DataColumn("DisplayCartTag", GetType(String))) '1st data level 6
    dt(x, y).Columns.Add(New DataColumn("ShipmentRecieved", GetType(String))) '3rd data level 7
    dr = dt(x, y).NewRow()

    If Not IsDBNull(rowMbr("QtyCarted")) Then 'QtyCarted
    dr(0) = Trim(rowMbr("QtyCarted"))
    Else
    dr(0) = ""
    End If
    If Not IsDBNull(rowMbr("Item")) Then 'Item
    dr(1) = Trim(rowMbr("Item"))
    Else
    dr(1) = ""
    End If
    If Not IsDBNull(rowMbr("Length")) Then 'Length
    dr(2) = Trim(rowMbr("Length"))
    Else
    dr(2) = ""
    End If
    If Not IsDBNull(rowMbr("Color")) Then 'Color
    dr(3) = Trim(rowMbr("Color"))
    Else
    dr(3) = ""
    End If

    If Not IsDBNull(rowMbr("PkgType")) Then 'PkgType
    dr(4) = Trim(rowMbr("PkgType"))
    Else
    dr(4) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayShipNo")) Then 'DisplayShipNo
    dr(5) = Trim(rowMbr("DisplayShipNo"))
    Else
    dr(5) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayCartTag")) Then 'DisplayCartTag
    dr(6) = Trim(rowMbr("DisplayCartTag"))
    Else
    dr(6) = ""
    End If

    If Not IsDBNull(rowMbr("ShipmentRecieved")) Then 'ShipmentRecieved
    dr(7) = Trim(rowMbr("ShipmentRecieved"))
    Else
    dr(7) = ""
    End If
    dt(x, y).Rows.Add(dr)
    Else 'Previous Cart ;add another row to previous Cart

    dr = dt(x, y).NewRow()

    If Not IsDBNull(rowMbr("QtyCarted")) Then 'QtyCarted
    dr(0) = Trim(rowMbr("QtyCarted"))
    Else
    dr(0) = ""
    End If
    If Not IsDBNull(rowMbr("Item")) Then 'Item
    dr(1) = Trim(rowMbr("Item"))
    Else
    dr(1) = ""
    End If
    If Not IsDBNull(rowMbr("Length")) Then 'Length
    dr(2) = Trim(rowMbr("Length"))
    Else
    dr(2) = ""
    End If
    If Not IsDBNull(rowMbr("Color")) Then 'Color
    dr(3) = Trim(rowMbr("Color"))
    Else
    dr(3) = ""
    End If

    If Not IsDBNull(rowMbr("PkgType")) Then 'PkgType
    dr(4) = Trim(rowMbr("PkgType"))
    Else
    dr(4) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayShipNo")) Then 'DisplayShipNo
    dr(5) = Trim(rowMbr("DisplayShipNo"))
    Else
    dr(5) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayCartTag")) Then 'DisplayCartTag
    dr(6) = Trim(rowMbr("DisplayCartTag"))
    Else
    dr(6) = ""
    End If

    If Not IsDBNull(rowMbr("ShipmentRecieved")) Then 'ShipmentRecieved
    dr(7) = Trim(rowMbr("ShipmentRecieved"))
    Else
    dr(7) = ""
    End If
    dt(x, y).Rows.Add(dr)
    End If 'end to cart logic
    Else 'prevShipNo
    If sCartNo <> prevCartNo Then 'New CartNo
    If x > 0 And y > 0 Then 'if x and y are zero than no cart exists yet
    If dt(x, y).Rows.Count > 0 Then
    CreateDataGrid(x, y, dt(x, y))
    End If
    End If
    y += 1 'increment cart count

    CartNo(x, y) = sCartNo
    prevCartNo = CartNo(x, y)
    CreateLabel(x, y, CartNo(x, y))

    dt(x, y) = New DataTable

    dt(x, y).Columns.Add(New DataColumn("QtyCarted", GetType(String))) '3rd data level 0
    dt(x, y).Columns.Add(New DataColumn("Item", GetType(String))) '3rd data level 1
    dt(x, y).Columns.Add(New DataColumn("Lenght", GetType(String))) '3rd data level 2
    dt(x, y).Columns.Add(New DataColumn("Color", GetType(String))) '3rd data level 3
    dt(x, y).Columns.Add(New DataColumn("PkgType", GetType(String))) '3rd data level 4
    dt(x, y).Columns.Add(New DataColumn("DisplayShipNo", GetType(String))) '1st data level 5
    dt(x, y).Columns.Add(New DataColumn("DisplayCartTag", GetType(String))) '1st data level 6
    dt(x, y).Columns.Add(New DataColumn("ShipmentRecieved", GetType(String))) '3rd data level 7
    dr = dt(x, y).NewRow()

    If Not IsDBNull(rowMbr("QtyCarted")) Then 'QtyCarted
    dr(0) = Trim(rowMbr("QtyCarted"))
    Else
    dr(0) = "Not Shipped"
    End If
    If Not IsDBNull(rowMbr("Item")) Then 'Item
    dr(1) = Trim(rowMbr("Item"))
    Else
    dr(1) = ""
    End If
    If Not IsDBNull(rowMbr("Length")) Then 'Length
    dr(2) = Trim(rowMbr("Length"))
    Else
    dr(2) = ""
    End If
    If Not IsDBNull(rowMbr("Color")) Then 'Color
    dr(3) = Trim(rowMbr("Color"))
    Else
    dr(3) = ""
    End If

    If Not IsDBNull(rowMbr("PkgType")) Then 'PkgType
    dr(4) = Trim(rowMbr("PkgType"))
    Else
    dr(4) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayShipNo")) Then 'DisplayShipNo
    dr(5) = Trim(rowMbr("DisplayShipNo"))
    Else
    dr(5) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayCartTag")) Then 'DisplayCartTag
    dr(6) = Trim(rowMbr("DisplayCartTag"))
    Else
    dr(6) = ""
    End If

    If Not IsDBNull(rowMbr("ShipmentRecieved")) Then 'ShipmentRecieved
    dr(7) = Trim(rowMbr("ShipmentRecieved"))
    Else
    dr(7) = ""
    End If
    dt(x, y).Rows.Add(dr)
    Else 'Previous Cart ;add another row to previous Cart

    dr = dt(x, y).NewRow()

    If Not IsDBNull(rowMbr("QtyCarted")) Then 'QtyCarted
    dr(0) = Trim(rowMbr("QtyCarted"))
    Else
    dr(0) = "Not Shipped"
    End If
    If Not IsDBNull(rowMbr("Item")) Then 'Item
    dr(1) = Trim(rowMbr("Item"))
    Else
    dr(1) = ""
    End If
    If Not IsDBNull(rowMbr("Length")) Then 'Length
    dr(2) = Trim(rowMbr("Length"))
    Else
    dr(2) = ""
    End If
    If Not IsDBNull(rowMbr("Color")) Then 'Color
    dr(3) = Trim(rowMbr("Color"))
    Else
    dr(3) = ""
    End If

    If Not IsDBNull(rowMbr("PkgType")) Then 'PkgType
    dr(4) = Trim(rowMbr("PkgType"))
    Else
    dr(4) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayShipNo")) Then 'DisplayShipNo
    dr(5) = Trim(rowMbr("DisplayShipNo"))
    Else
    dr(5) = ""
    End If

    If Not IsDBNull(rowMbr("DisplayCartTag")) Then 'DisplayCartTag
    dr(6) = Trim(rowMbr("DisplayCartTag"))
    Else
    dr(6) = ""
    End If

    If Not IsDBNull(rowMbr("ShipmentRecieved")) Then 'ShipmentRecieved
    dr(7) = Trim(rowMbr("ShipmentRecieved"))
    Else
    dr(7) = ""
    End If
    dt(x, y).Rows.Add(dr)
    End If 'end to cart logic

    End If 'end shipno logic
    Next
    'display final cart data grid
    If x > 0 And y > 0 Then 'x and y are initialized at zero they must be greater than zero to create a dt
    If dt(x, y).Rows.Count > 0 Then
    CreateDataGrid(x, y, dt(x, y))
    End If
    End If





    Catch oEx As Exception
    'send email to IT
    Dim Subject As String, Msg As String, TOEmail As String, CCEmail As String
    TOEmail = System.Configuration.ConfigurationSettings.AppSettings("ErrorEmail")
    Subject = "OptiFinish Error " & Now
    Msg = "Error in CartSummary.RetrieveReprint." & vbCrLf & vbCrLf & oEx.Message & vbCrLf & vbCrLf & "Source: " & oEx.Source & vbCrLf & vbCrLf & "Stack: " & oEx.StackTrace
    Dim oUtility As New Utility
    oUtility.SendEmail(Subject, Msg, TOEmail)

    'Display error to user, send email to scheduling
    'pnlReprint.Visible = False
    'pnlErrors.Visible = True
    'lblErrors.Text = " Reprinting Summary received an error."
    'Dim oUtl As OptiFinishLocalShippingBusiness.Utility = New OptiFinishLocalShippingBusiness.Utility
    ''lblErrorMessage.Text = oUtl.ITErrorMessage
    'lblErrorSteps.Text = "· Click Continue Button and return to Ready for Shipping screen
    " & _
    ' "· Go back into the same sales order by clicking Create Tag Button
    " & _
    ' "· Check saved tags to see if the one being created when error occurred has saved
    " & _
    ' "· If it did not save, try to it create again
    " & _
    ' "· If it saved, try to create another tag if required
    " & _
    ' "· If either of these steps cause another error, immediately call IT Programmer phone number shown on screen
    " & _
    ' "· Then try to create tags for another sales order make a copy of Shop Work Order and indicate number of pieces on cart(Hand Process)
    " & _
    ' "· If this order creates an error, ALL tags will have to be hand written until IT resolves problem
    " & _
    ' "· If the new order does not error, you should be able to Create Tags for other orders and will only have to hand Process tags for the sales order that has caused the error
    " & _
    ' "· Keep a copy of all hand Processed tags for entry when system is up"

    End Try
    End Sub





    Private Sub CreateLabel(ByVal x As Integer, ByVal ShipNo As String, ByVal ShipDate As String, ByVal ShippedBy As String, ByVal Driver As String, ByVal Addr1 As String)
    'declare dynamic label
    Dim lbl As Label = New Label
    Dim lblText As Label = New Label

    'set font style for bold
    lbl.Font.Bold = True
    lbl.Font.Size = Web.UI.WebControls.FontUnit.Medium
    lbl.Font.Name = "verdanda"
    lbl.EnableViewState = True
    lblText.Font.Bold = True
    lblText.Font.Size = Web.UI.WebControls.FontUnit.Medium
    lblText.Font.Name = "verdanda"
    lblText.EnableViewState = True

    Dim lbl1 As Label = New Label
    Dim lblText1 As Label = New Label

    'set font style for unbolded labels
    lbl1.Font.Italic = True
    lbl1.Font.Size = Web.UI.WebControls.FontUnit.Small
    lbl1.Font.Name = "verdanda"
    lbl1.EnableViewState = True
    lblText1.Font.Bold = True
    lblText1.Font.Size = Web.UI.WebControls.FontUnit.Small
    lblText1.Font.Name = "verdanda"
    lblText1.EnableViewState = True

    Dim lbl2 As Label = New Label
    Dim lblText2 As Label = New Label

    'set font style for unbolded labels
    lbl2.Font.Italic = True
    lbl2.Font.Size = Web.UI.WebControls.FontUnit.Small
    lbl2.Font.Name = "verdanda"
    lbl2.EnableViewState = True
    lblText2.Font.Bold = True
    lblText2.Font.Size = Web.UI.WebControls.FontUnit.Small
    lblText2.Font.Name = "verdanda"
    lblText2.EnableViewState = True

    Dim lbl3 As Label = New Label
    Dim lblText3 As Label = New Label

    'set font style for unbolded labels
    lbl3.Font.Italic = True
    lbl3.Font.Size = Web.UI.WebControls.FontUnit.Small
    lbl3.Font.Name = "verdanda"
    lbl3.EnableViewState = True
    lblText3.Font.Bold = True
    lblText3.Font.Size = Web.UI.WebControls.FontUnit.Small
    lblText3.Font.Name = "verdanda"
    lblText3.EnableViewState = True

    Dim lbl4 As Label = New Label
    Dim lblText4 As Label = New Label

    'set font style for unbolded labels
    lbl4.Font.Italic = True
    lbl4.Font.Size = Web.UI.WebControls.FontUnit.Small
    lbl4.Font.Name = "verdanda"
    lbl4.EnableViewState = True
    lblText4.Font.Bold = True
    lblText4.Font.Size = Web.UI.WebControls.FontUnit.Small
    lblText4.Font.Name = "verdanda"
    lblText4.EnableViewState = True

    'lbl ShipNo
    lbl.Text = "
    " & "
    " & "
    " & "
    " & "Ship No:" & ""
    lblText.Text = ShipNo & ""

    pnlShip.Controls.Add(lbl)
    pnlShip.Controls.Add(lblText)

    lbl.ID = "lbl_" & x
    lblText.ID = "lblShipNo_" & x

    'lbl1 ShipDate
    lbl1.Text = "Ship Date:" & ""
    lblText1.Text = ShipDate & ""

    pnlShip.Controls.Add(lbl1)
    pnlShip.Controls.Add(lblText1)

    lbl1.ID = "lbl1_" & x
    lblText1.ID = "lblShipDate_" & x

    'lbl2 ShippedBy
    lbl2.Text = "ShippedBy:" & ""
    lblText2.Text = ShippedBy & "
    "

    pnlShip.Controls.Add(lbl2)
    pnlShip.Controls.Add(lblText2)

    lbl2.ID = "lbl2_" & x
    lblText2.ID = "lblShipDate_" & x

    'lbl3 Driver
    lbl3.Text = "" _
    & "&nbsp" & "Driver :" & ""
    lblText3.Text = Driver & ""

    pnlShip.Controls.Add(lbl3)
    pnlShip.Controls.Add(lblText3)

    lbl3.ID = "lbl3_" & x
    lblText3.ID = "lblDriver_" & x

    'lbl4 Addr1
    lbl4.Text = "Deliver To:" & ""
    lblText4.Text = Addr1 & "
    "

    pnlShip.Controls.Add(lbl4)
    pnlShip.Controls.Add(lblText4)

    lbl4.ID = "lbl4_" & x
    lblText4.ID = "lblAddr1_" & x

    End Sub

    Private Sub CreateLabel(ByVal x As Integer, ByVal y As Integer, ByVal Text As String)
    'declare dynamic label
    Dim lbl As Label = New Label
    Dim lblText As Label = New Label

    lbl.Font.Bold = True
    lbl.Font.Size = Web.UI.WebControls.FontUnit.Small
    lbl.Font.Name = "verdanda"
    lbl.EnableViewState = True
    lblText.Font.Bold = True
    lblText.Font.Size = Web.UI.WebControls.FontUnit.Small
    lblText.Font.Name = "verdanda"
    lblText.EnableViewState = True

    lbl.Text = "
    " & "" & "Cart No: "
    lblText.Text = Text & "
    "

    pnlShip.Controls.Add(lbl)
    pnlShip.Controls.Add(lblText)

    lbl.ID = "lbl_" & x & "_" & y
    lblText.ID = "lblCartNo_" & x & "_" & y
    End Sub

    Private Sub CreateDataGrid(ByVal x As Integer, ByVal y As Integer, ByVal dt As DataTable)
    Dim dg As DataGrid = New DataGrid
    Dim dgc As DataColumn
    Dim i As Integer = 0
    Dim dr As DataRow
    Dim tc As TemplateColumn
    Dim _item As DataGridItem

    'set dg properties
    Dim temp As String
    temp = dg.EnableViewState.ToString

    pnlShip.Controls.Add(dg)

    dg.AutoGenerateColumns = True
    'Dim sCheckBoxID As String = "TemplateColumn"
    Dim tcol As New TemplateColumn
    With tcol
    .HeaderText = "Recieved"
    .ItemTemplate = New MyItemTemplate("cbx")
    End With
    dg.Columns.Add(tcol)


    dg.DataSource = New DataView(dt)
    dg.DataBind()

    'loop through datagrid set check box
    For i = 0 To dg.Items.Count - 1
    _item = dg.Items(i)
    Dim cbx As CheckBox = _item.FindControl("cbx")
    If Trim(_item.Cells(8).Text) > "" Then
    If Trim(_item.Cells(8).Text) = "Y" Then
    cbx.Checked = True
    Else
    cbx.Checked = False
    End If
    Else
    cbx.Checked = False
    End If

    Next
    'change Id to make Datagrid unique to allow next datagrid to use dg as a name
    dg.ID = "dg_" & x & y

    End Sub

    Public Sub UpdateCheckBoxes(ByVal dg As DataGrid)

    Dim i As Integer = 0
    Dim _item As DataGridItem
    'loop through datagrid set check box
    For i = 0 To dg.Items.Count - 1
    _item = dg.Items(i)
    Dim cbx As CheckBox = _item.FindControl("cbx")

    If cbx.Checked = True Then
    _item.Cells(8).Text = "Y"
    Else
    _item.Cells(8).Text = ""
    End If
    Next
    End Sub

    Protected Overrides Sub Loadviewstate(ByVal savedstate As Object)
    MyBase.LoadViewState(savedstate)
    Dim i As Integer = 0
    Dim _item As DataGridItem
    'loop through datagrid set check box
    Dim dg As DataGrid
    Dim c As Control
    'loop through datagrids
    For Each c In Me.pnlShip.Controls
    Dim t = c.GetType.ToString
    Dim id = c.ID

    If t Like "" Then
    UpdateCheckBoxes(c)
    End If

    Next
    'RetrieveShipmentDetail(lblSort.Text, lblAsc.Text)
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

    Dim dg As DataGrid
    Dim c As Control
    'loop through datagrids
    For Each c In Me.pnlShip.Controls
    Dim t = c.GetType.ToString
    Dim id = c.ID

    If t Like "" Then
    UpdateCheckBoxes(c)
    End If

    Next
    End Sub









    Public Class MyItemTemplate
    Implements ITemplate

    Private colID As String

    Sub New(ByVal str As String)
    colID = str
    End Sub


    Public Overridable Overloads Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
    Dim oCheckBox As CheckBox = New CheckBox
    oCheckBox.EnableViewState = True
    oCheckBox.AutoPostBack = False
    oCheckBox.ID = colID
    AddHandler oCheckBox.DataBinding, AddressOf BindCheckBox
    AddHandler oCheckBox.CheckedChanged, AddressOf CheckBoxCheckChangedHandler

    'oCheckBox.Checked = getRecievedShipment
    container.Controls.Add(oCheckBox)
    End Sub

    Public Sub BindCheckBox(ByVal sender As Object, ByVal e As EventArgs)
    Dim oCheckBox As CheckBox = CType(sender, CheckBox)
    'oCheckBox.AutoPostBack = True
    Dim container As DataGridItem = CType(oCheckBox.NamingContainer, DataGridItem)
    oCheckBox.EnableViewState = True
    oCheckBox.Checked = False

    End Sub

    Public Sub CheckBoxCheckChangedHandler(ByVal sender As Object, ByVal e As EventArgs)


    End Sub
    End Class





    End Class





    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
     
  2. Ok a couple of points in the right direction.

    check out the event, ItemDataBound, much simpler than using all of the template stuff.

    With this event you can dynamically create controls and add them to any column in the datagrid.

    Datagrids are very messy to get working as I have found when you start getting into templates, problems with postbacks especially on complex pages.

    I almost do everything on ItemDataBound, and since have never had any problems, missing any data.

    Michael
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page