View Single Post
  #15 (permalink)  
Old 11-09-09, 00:17
Access Junkie Access Junkie is offline
Registered User
 
Join Date: Jun 2006
Posts: 72
[post broken into two due to max post length restrictions]

I got everything working how i want it to now .

Teddy, the javascript that you posted did not work for me. I think the problem was that it did not recognise "forms". What did work is below. I have to thank you nonetheless because your example was what I needed to get onto the right track.

Code:
<script type="text/jscript">
<!--
    function SetRepGroup() 
    {
        myField = form1.elements("SelecedReportGroup");
        var e = document.getElementById("ddlistReportGroup"); // select element
        var myValue = e.options[e.selectedIndex].value
        myField.value = myValue
    }
//-->
</script>
In case anyone reading this thread is interested, my code for the page_init is...

Code:
    Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Dim i As Integer
        Dim SQL As String
        Dim sqlconn As New SqlConnection

        sqlconn.ConnectionString = SQLConnString
        sqlconn.Open()

        If IsPostBack Then
            SQL = "SELECT DISTINCT MethProdTechVerLists.MPTVID, Methods.ShortName, ProductsTested.ShortDesc AS ProdShort,  " _
                    + "Techniques.ShortDesc AS TechShort, ResultDetails.Version, MethProdTechVerLists.[Order] " _
                + "FROM MethProdTechVerLists INNER JOIN " _
                      + "ResultDetails ON MethProdTechVerLists.MPTVID = ResultDetails.MPTVID INNER JOIN " _
                      + "Methods ON ResultDetails.MethodID = Methods.MethodID INNER JOIN " _
                      + "ProductsTested ON ResultDetails.ProductTested = ProductsTested.ProductTested INNER JOIN " _
                      + "Techniques ON ResultDetails.Technique = Techniques.Technique " _
                + "WHERE MethProdTechVerLists.ReportGroupID='" + Request.Params("SelecedReportGroup") + "' " _
                + "ORDER BY MethProdTechVerLists.[Order]"
            Dim sqlComm As New SqlCommand(SQL, sqlconn)
            Dim r As SqlDataReader = sqlComm.ExecuteReader()

            For i = 14 To gvTestGrid.Columns.Count - 1
                gvTestGrid.Columns.Remove(gvTestGrid.Columns(14))
            Next
            i = 0
            While r.Read()
                Dim MPTVID As Integer = CInt(r("MPTVID"))
                Dim ShortMeth As String = r("ShortName")
                Dim ShortProd As String = r("ProdShort")
                Dim ShortTech As String = r("TechShort")
                Dim ShortVer As String = r("Version")

                Dim tf As New TemplateField()

                Dim headerTemp As New MyHeaderTemplate()
                headerTemp.HeadingText = ShortMeth + "<br />" + ShortProd + "<br />" + ShortTech + "<br />" + "Ver " + ShortVer
                headerTemp.MPTVID = MPTVID
                tf.HeaderTemplate = headerTemp

                Dim itemTemp As New MyItemTemplate()
                itemTemp.MPTVID = MPTVID
                tf.ItemTemplate = itemTemp

                tf.ItemStyle.Width = 4

                gvTestGrid.Columns.Add(tf)

                i += 1
            End While
        End If
    End Sub
My code for the MyItemTemplate class is...

Code:
Imports System.Data.SqlClient
Imports agric.wa.gov.au.AnnualDB.BusinessEntities
Imports agric.wa.gov.au.AnnualDB.BusinessLogic
Imports agric.wa.gov.au.AnnualDB.WebApp
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls.Button
Imports System.Web.UI.HtmlControls
Imports System.Text
Imports System.Configuration
Imports System.Configuration.ConfigurationManager

Public Class MyItemTemplate
    Implements ITemplate
    'Expose the command event handler - when the command event handler is trapped internally this event is raised to inform the container 
    Public Event LinkButtonCommand As CommandEventHandler
    'Public Event LinkButtonClick As EventHandler 
    Private m_sMPTVID As String

    Public Property MPTVID() As String
        Get
            Return m_sMPTVID
        End Get
        Set(ByVal value As String)
            m_sMPTVID = value
        End Set
    End Property

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Dim text As New Label
        text.Style.Add("display", "block")
        'text.Style.Add("width", "4px")
        text.Style.Add("float", "left")

        AddHandler Text.DataBinding, AddressOf Me.BindText
        container.Controls.Add(Text)


        Dim lnkBtn As New LinkButton
        'lnkBtn.Style.Add("float", "left")
        AddHandler lnkBtn.DataBinding, AddressOf Me.BindLinkButtons
        'AddHandler lnkBtn.Click, New EventHandler(AddressOf Click)
        AddHandler lnkBtn.Command, New CommandEventHandler(AddressOf Command)
        container.Controls.Add(lnkBtn)
    End Sub

    Private Sub BindLinkButtons(ByVal sender As Object, ByVal e As EventArgs)
        Dim lnkBtn As LinkButton = CType(sender, LinkButton)
        Dim container As GridViewRow = CType(lnkBtn.NamingContainer, GridViewRow)
        'Dim cellContent As String = DataBinder.Eval(container.DataItem, "Content").ToString
        Dim cellContent As String = DataBinder.Eval(container.DataItem, MPTVID).ToString
        lnkBtn.Text = cellContent
        'lnkBtn.CommandName = MPTVID
        lnkBtn.CommandName = "ite" + DataBinder.Eval(container.DataItem, "SampleBarcode").ToString()
        lnkBtn.CommandArgument = "ite" + MPTVID
    End Sub

    Private Sub BindText(ByVal sender As Object, ByVal e As EventArgs)
        Dim txt As Label = CType(sender, Label)
        Dim row As GridViewRow = CType(txt.NamingContainer, GridViewRow)
        Dim cellContent As String = DataBinder.Eval(row.DataItem, MPTVID).ToString
        'txt.Text = MPTVID + ": "
    End Sub

    ''This will crash because the only event that's bubbled up is the Command Event....which takes a parameter of CommandEventArgs 
    'Private Sub Click(ByVal sender As Object, ByVal e As EventArgs) 
    '    RaiseEvent LinkButtonClick(Me, e) 
    'End Sub 

    'Handles the Command Event:  
    'When the link button is clicked the Command event is bubbled up to the container, which happens to be this class. 
    'This method bubbles the event up to the next level so that the event can be 
    'handled in the Page. 
    Private Sub Command(ByVal sender As Object, ByVal e As CommandEventArgs)
        RaiseEvent LinkButtonCommand(Me, e)
    End Sub

End Class
And my code for the MyHeaderTemplate class is...
Reply With Quote