views:

59

answers:

0

Hello

I am using Infragistics tools in my application. Here I am using a web panel which has a details view, text boxes,buttons and a couple of list boxes and all the above are created dynamically in a repeater control. The items in one listbox are moved on to the next listbox when i click a dynamic button which has id btnNavi.

When i am trying to add the second item for that listbox, it is treating it as a new listbox, meanwhile the first added item is getting replaced with the second item.

Please find the code below:

<asp:Panel ID="Panel1" runat="server">

   <asp:Label ID="Label1" runat="server" Text="Visible"></asp:Label>
   <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <ContentTemplate>
   <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
       <igmisc:WebPanel ID="WebPanel4" runat="server"   ForeColor="#003366" Expanded="false" Width="100%">
         <Template>
       <asp:DetailsView runat="server" Height="50px" Width="125px" ID="dv1" >
       </asp:DetailsView>
       <asp:Panel runat="server" Id="Panel2" >
           </asp:Panel>
       </Template>

      </igmisc:WebPanel> 

     </ItemTemplate>
   </asp:Repeater>
   </ContentTemplate>
 </asp:UpdatePanel>

Partial Public Class _Default
    Inherits System.Web.UI.Page


Dim i As Integer = 0


Dim ds As New DataSet()


Public con As New SqlConnection(ConfigurationManager.ConnectionStrings("POSConnectionString").ConnectionString)


Dim mainNode, rootNode, subRootNode, discRootNode, progRootNode, progRootNode1, areaRootNode, grpRootNode, subgrpNode As Node


Dim Str, grpID1 As String
Dim ht As New List(Of String)
Public link As New LinkButton
Dim a2 As New Infragistics.WebUI.Misc.WebPanel()
Dim a1 As New DetailsView()
Dim a4 As New Panel()
Dim count As Integer = 0
Dim str1 As String

Dim txtGName As New TextBox()
Dim txtGAbb As New TextBox()
Dim dddValue As New DropDownList()
Dim txtMNO As New TextBox()
Dim btnupDate As New Button()
Dim btnInAct As New Button()
Dim lb As New ListBox()
Dim lb1 As New ListBox()
Dim btnNav As New Button()

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    con.Open()


    Repeater1.DataSource = [gett]()
    Repeater1.DataBind()

    Dim j As Integer = 0
    For Each repeatitem As RepeaterItem In Repeater1.Items
        Dim cmd3 As New SqlDataAdapter("select * from requirementsgroups where groupname='" + ([gett]().Tables(0).Rows(repeatitem.ItemIndex)(0)).ToString() + "' and areaid='147' and status='Act'", con)
        Dim repeaterItem As New RepeaterItem(repeatitem.ItemIndex, ListItemType.Item)

        a2 = DirectCast(Repeater1.Items(j).FindControl("WebPanel4"), Infragistics.WebUI.Misc.WebPanel)
        a1 = DirectCast(a2.FindControl("dv1"), DetailsView)
        a4 = DirectCast(a2.FindControl("Panel2"), Panel)
        ' a3 = DirectCast(a2.FindControl("ebImage"), ImageButton) '
        Dim areaDs As New DataSet()
        cmd3.Fill(areaDs)
        a1.DataSource = areaDs
        a1.DataBind()

        a2.ID = ([gett]().Tables(0).Rows(repeatitem.ItemIndex)(0)).ToString()
        a2.Header.Text = a1.Rows(3).Cells(1).Text
        a2.Header.BackColor = Drawing.Color.AliceBlue
        a2.Header.Height = Unit.Pixel(30)
        a2.Header.Font.Bold = True
        a2.Header.Font.Size = FontUnit.Point(15)

        a4.ID = "pa" + a1.Rows(0).Cells(1).Text


        txtGName = New TextBox()
        txtGName.ID = "txtGName" + a1.Rows(0).Cells(1).Text
        a4.Controls.Add(txtGName)

        txtGAbb = New TextBox()
        txtGAbb.ID = "txtGAbb" + a1.Rows(0).Cells(1).Text
        a4.Controls.Add(txtGAbb)

        dddValue = New DropDownList()
        dddValue.ID = "ddlSelect" + a1.Rows(0).Cells(1).Text
        dddValue.Items.Add(New ListItem("M:N", "M:N"))
        dddValue.Items.Add(New ListItem("Single Course", "Single Course"))
        dddValue.Items.Add(New ListItem("Others", "Others"))
        a4.Controls.Add(dddValue)

        txtMNO = New TextBox()
        txtMNO.ID = "txtMNO" + a1.Rows(0).Cells(1).Text
        a4.Controls.Add(txtMNO)

        btnupDate = New Button()
        btnupDate.Text = "Update"
        btnupDate.ID = "btn" + a1.Rows(0).Cells(1).Text
        btnupDate.CommandName = a1.Rows(0).Cells(1).Text
        AddHandler (btnupDate.Command), AddressOf update_Command
        a4.Controls.Add(btnupDate)

        btnInAct = New Button()
        btnInAct.Text = "Inactive"
        btnInAct.ID = "btninAct" + a1.Rows(0).Cells(1).Text
        btnInAct.CommandName = a1.Rows(0).Cells(1).Text
        AddHandler (btnInAct.Command), AddressOf inActive_Command

        btnNav = New Button()
        btnNav.Text = ">>"
        btnNav.ID = "btnNavi"
        btnNav.CommandName = a1.Rows(0).Cells(1).Text
        AddHandler (btnNav.Command), AddressOf btnNav_Command


        Dim a3 As New ImageButton()
        a3.ID = a1.Rows(0).Cells(1).Text
        a3.ImageUrl = "~/edit.jpg"
        a3.CommandName = a1.Rows(0).Cells(1).Text
        a3.Attributes.Add("runAt", "server")
        AddHandler a3.Command, AddressOf lnkViewJob_Command

        lb = New ListBox()
        lb.ID = "lb1"
        Dim ji As New SqlCommand("select coursenumber+' '+coursename,coursenumber from courses", con)
        Dim oi As SqlDataReader = ji.ExecuteReader()
        While oi.Read()
            lb.Items.Add(New ListItem(oi(0).ToString(), oi(1).ToString()))
        End While
        oi.Close()
        lb1 = New ListBox()
        lb1.ID = "lb2"

        a2.Controls.Add(a1)
        a2.Controls.Add(a3)
        a2.Controls.Add(a4)
        Repeater1.Controls.Add(a2)
        a2.Controls.Add(lb)
        a2.Controls.Add(btnNav)
        a2.Controls.Add(lb1)
        repeaterItem = New RepeaterItem(repeaterItem.ItemIndex, ListItemType.Separator)
        Dim ltr As New LiteralControl()
        ltr.Text = "<hr />"
        Repeater1.Controls.Add(ltr)

        j = j + 1
    Next
End Sub

Public Sub btnNav_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Dim x As String = e.CommandName.ToString()
    Dim selectCmd As New SqlCommand("select groupabber,groupname,groupoption,minimumnumber from requirementsgroups where groupid='" + x + "'", con)
    Dim selectRead As SqlDataReader = selectCmd.ExecuteReader()

    'txtGName = DirectCast(a4.FindControl("txtGName121"), TextBox)'
    Dim str As String = String.Empty
    While selectRead.Read()
        str = selectRead(1).ToString()
    End While
    selectRead.Close()
    a2 = DirectCast(Repeater1.FindControl(str), Infragistics.WebUI.Misc.WebPanel)
    a4 = DirectCast(a2.FindControl("pa" + x), Panel)
    lb = DirectCast(a2.FindControl("lb1"), ListBox)
    lb1 = DirectCast(a2.FindControl("lb2"), ListBox)
    lb1.Items.Add(lb.SelectedItem.Text)
End Sub

Public Sub inActive_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Dim x As String = e.CommandName.ToString()
    Dim selectCmd As New SqlCommand("select groupabber,groupname,groupoption,minimumnumber from requirementsgroups where groupid='" + x + "'", con)
    Dim selectRead As SqlDataReader = selectCmd.ExecuteReader()

    'txtGName = DirectCast(a4.FindControl("txtGName121"), TextBox)'
    Dim str As String = String.Empty
    While selectRead.Read()
        str = selectRead(1).ToString()
    End While
    selectRead.Close()
    a2 = DirectCast(Repeater1.FindControl(str), Infragistics.WebUI.Misc.WebPanel)
    a2.Visible = False
End Sub
Public Sub update_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Dim x As String = e.CommandName.ToString()
    Dim selectCmd As New SqlCommand("select groupabber,groupname,groupoption,minimumnumber from requirementsgroups where groupid='" + x + "'", con)
    Dim selectRead As SqlDataReader = selectCmd.ExecuteReader()

    'txtGName = DirectCast(a4.FindControl("txtGName121"), TextBox)'
    Dim str As String = String.Empty
    While selectRead.Read()
        str = selectRead(1).ToString()
    End While
    selectRead.Close()
    a2 = DirectCast(Repeater1.FindControl(str), Infragistics.WebUI.Misc.WebPanel)
    a4 = DirectCast(a2.FindControl("pa" + x), Panel)
    Dim x1 As String = DirectCast(a4.FindControl("txtGName" + x), TextBox).Text
    Dim x2 As String = DirectCast(a4.FindControl("txtGAbb" + x), TextBox).Text
    Dim x3 As String = DirectCast(a4.FindControl("ddlSelect" + x), DropDownList).SelectedItem.Text
    Dim x4 As String = DirectCast(a4.FindControl("txtMNO" + x), TextBox).Text

End Sub

Public Sub lnkViewJob_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Dim x As String = e.CommandName.ToString()
    Dim selectCmd As New SqlCommand("select groupabber,groupname,groupoption,minimumnumber from requirementsgroups where groupid='" + x + "'", con)
    Dim selectRead As SqlDataReader = selectCmd.ExecuteReader()

    'txtGName = DirectCast(a4.FindControl("txtGName121"), TextBox)'
    Dim str As String = String.Empty
    While selectRead.Read()
        str = selectRead(1).ToString()
    End While
    selectRead.Close()
    a2 = DirectCast(Repeater1.FindControl(str), Infragistics.WebUI.Misc.WebPanel)
    a4 = DirectCast(a2.FindControl("pa" + x), Panel)
    txtGName = DirectCast(a4.FindControl("txtGName" + x), TextBox)
    txtGAbb = DirectCast(a4.FindControl("txtGAbb" + x), TextBox)
    dddValue = DirectCast(a4.FindControl("ddlSelect" + x), DropDownList)
    txtMNO = DirectCast(a4.FindControl("txtMNO" + x), TextBox)
    Dim selectRead1 As SqlDataReader = selectCmd.ExecuteReader()
    While selectRead1.Read()
        txtGName.Text = selectRead1(0).ToString()
        txtGAbb.Text = selectRead1(1).ToString()
        dddValue.SelectedValue = selectRead1(2).ToString()
        txtMNO.Text = selectRead1(3).ToString()
    End While
    selectRead1.Close()
End Sub

Public Function [gett]() As DataSet
    Try
        con.Close()
        con.Open()
        Dim fff As String = "select a.areaid,p.programname,d.disciplinename from programareas a inner join "
        fff += "programs p on p.programid=a.programid inner join disciplines d "
        fff += "on d.discid=p.discid where a.areaid='1' "
        Dim jk As New SqlCommand(fff, con)
        Dim lk As SqlDataReader = jk.ExecuteReader()
        While lk.Read()
            Session("PrgAbr") = lk(1).ToString()
            Session("DiscAbr") = lk(2).ToString()
            Session("as") = lk(0).ToString()
        End While
        lk.Close()

        Dim cmd As New SqlCommand("select groupname from RequirementsGroups RG inner join ProgramAreas PA on RG.AreaID=PA.AreaID where PA.AreaID='147' and RG.status='Act'", con)
        Dim da As New SqlDataAdapter(cmd)
        Dim ds5 As New DataSet()
        cmd.ExecuteNonQuery()
        da.Fill(ds5, "RequirementsGroups")
        Return (ds5)
    Catch
    End Try
End Function

Protected Sub Repeater1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Repeater1.PreRender

End Sub

End Class

Thanks in Advance.