?
Solved

Help with creating multiple tables within a For next Loop

Posted on 2012-08-13
39
Medium Priority
?
535 Views
Last Modified: 2012-08-18
Hi,

I am using the code below to pass data to a combobox depending on values found in a link file, problem is it only works when one record is found, how do I modify the code in Part A when mulktiple records are found, for example how do I create  utubeC1 for first match, utubeC2 for second match, utubeC3 for third match?

An in Part B how do I modify the code to see data in utubeC1, utubeC2, utube C2 etc.., I will have Next and Previous buttons to move to diffrent records.

Thanks,

Victor
Part A:
            For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/LinkA[Item_ID='" & C1Item.SelectedItem.Value & "']")

      For Each xnCountry As Xml.XmlNode In xdCountry.SelectNodes("/Root/CountryTable[contains('," & CountryID & ",', concat(',', Country_ID, ','))]")
                        CountryID2 = xnCountry.SelectSingleNode("Country_ID").InnerText
                        Name = xnCountry.SelectSingleNode("Country").InnerText
                        dtCountry.Rows.Add({CountryID2, Name})
                      *****************
                       For Loop  
                        utubeC(1) += Name & ","
                      Next
                     ******************
                    Next

                    If utubeC <> "" Then
                        utubeC = utubeC.Substring(0, utubeC.Length - 1) 'To remove last semicolon
                    End If
  Next
                   
Part B:
            Dim Country As New DataSet
            Country.ReadXml(Server.MapPath("~/App_Data/Country.xml"))
            C1Country.DataSource = Country.Tables(0)
            C1Country.DataTextField = "Country"
            C1Country.DataValueField = "Country_ID"
            C1Country.DataBind()
            C1Country.ClearSelection()
            If utubeC IsNot Nothing Then
                For i As Integer = 0 To C1Country.Items.Count - 1
                    If utubeC.Split(",").Contains(C1Country.Items(i).Text) Then
                        C1Country.Items(i).Selected = True
                        Dim CB As CheckBox = C1Country.Items(i).FindControl("CheckCountry")
                        CB.Checked = True
                    End If
                Next
            End If
0
Comment
Question by:vcharles
  • 22
  • 15
  • 2
39 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 38290977
Can u using an index instead of 1

utubeC(1)

utubeC(index)
0
 

Author Comment

by:vcharles
ID: 38291667
I can but how do I inclue the index in the main For loop?

For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/LinkA[Item_ID='" & C1Item.SelectedItem.Value & "']")

Thanks,

V.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38292856
I'm not sure of VB sorry

but in C# I would just do sumthing like this

utubeC[index++]= Name + ",";
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:vcharles
ID: 38294071
I tried to convert it to VB.NET (code below)

utubeC(System.Math.Max(System.Threading.Interlocked.Increment(index),index - 1)) = Name & ","

But it's not the proper code, will look into another way to convert it.

Thanks,

Victor
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38294796
hi again ,

  Are you try like this ?

"I will have Next and Previous buttons to move to diffrent records"


whether  next and previous button cause postback???
   if yes , then you cant use array ie utubec as this will clear every time on postback.

Your approach should be like ,
  Store it in hidden variable or view state instead of utubec then get that value in the next / previous button accordingly and display your result as you do in the partb.

  *****************
                       For Loop   
                        'utubeC(1) += Name & ","
                        viewstate("utubec") &= Name & ","
                      Next
******************

Open in new window


On your next/previous action  [ i hope part b is your next/previous action code right?]
  1.Receive the value from viewstate("utubec")
  2.Checking You current index of the screen using viewstate("currentindex")
  3.If , viewstate("currentindex") null moving to next page
  4.Other wise , you have to configure according for next / previous action.
  5.Storing back with viewstate("currentindex") with the new value

Is this your looking for ?


Meeran03
0
 

Author Comment

by:vcharles
ID: 38295416
Hi,

Part B in my previous post  just displays the data,  below is more detais on my issue, not certain using View State will help with showing data for one match at a time. I think somehow each match needs data in a separate table.

In Part A, I am trying to view the data in a listbox  and  in Part B, I am trying to view the data in a combobox with checkboxes, both controls need to display data for one record at a time. I think one solution can solve both problems.  Will View State help resolve the issues in Parts A and B? Part C shows data in mx next button, but I don't know how to include the code for the listbox and combobox contrls.

Part A:
Searh Method:

For Each xnNSN As Xml.XmlNode In xdNSN.SelectNodes("/Root/NSNTable[contains('," & NSNID & ",', concat(',', NSN_ID, ','))]")
                    NSNID2 = xnNSN.SelectSingleNode("NSN_ID").InnerText
                    Name = xnNSN.SelectSingleNode("NSN").InnerText
                    dtNSN.Rows.Add({NSNID2, Name})
    Next

View Method:
C1NSN.Items.Clear()
C1NSN.DataSource = dtNSN
C1NSN.DataTextField = "NSN"
C1NSN.DataValueField = "NSN_ID"
C1NSN.DataBind()

Issue:  Listbox shows data for multiple records in Link file, for example if I am searching  for ItemA_ID = 5, and my link file contains
<ItemA_ID>5</ItemA_ID>
<NSN_ID> 1,2</NSN_ID>
<ItemA_ID>5</ItemA_ID>
<NSN_ID> 3,5</NSN_ID>
Listbox displays data for both records, need it to display data for the first match and when I press Next show data for the second match.

Part B:
Searh Method:

For Each xnSDeactivation As Xml.XmlNode In xdSDeactivation.SelectNodes("/Root/SDeactivationTable[contains('," & SDeactivationID & ",', concat(',', SDeactivation_ID, ','))]")
                    SDeactivationID2 = xnSDeactivation.SelectSingleNode("SDeactivation_ID").InnerText
                    Name = xnSDeactivation.SelectSingleNode("SDeactivation").InnerText
                    dtSDeactivation.Rows.Add({SDeactivationID2, Name})
                    utubeC += Name & ","
                Next
                If utubeC <> "" Then
                    utubeC = utubeC.Substring(0, utubeC.Length - 1) 'To remove last semicolon
                End If

View Method:
Dim SDeactivation As New DataSet
            SDeactivation.ReadXml(Server.MapPath("~/App_Data/SDeactivation.xml"))
            C1SDeactivation.DataSource = SDeactivation.Tables(0)
            C1SDeactivation.DataTextField = "SDeactivation"
            C1SDeactivation.DataValueField = "SDeactivation_ID"
            C1SDeactivation.DataBind()
            C1SDeactivation.ClearSelection()
            If utubeC IsNot Nothing Then
                For i As Integer = 0 To C1SDeactivation.Items.Count - 1
                    If utubeC.Split(",").Contains(C1SDeactivation.Items(i).Text) Then
                        C1SDeactivation.Items(i).Selected = True
                        Dim CB As CheckBox = C1SDeactivation.Items(i).FindControl("CheckSDeactivation")
                        CB.Checked = True
                    End If
                Next
            End If

Issue: The correct checkboxes are not checked because all matching records are displayed in the combobox instead of one record at a time.

Part C:

Next Button:
(How do I include the code to view data in the Listbox and Combobox?) , all is ok with dtReceiver because there’s always a single entry (<Country_ID> 1</Country_ID>) in the link  file.
dtSDeactivation = Session("dtSDeactivation")
dtNSN = Session("dtNSN")
dtReceiver = Session("dtReceiver")
CurrentIndex = Session("CurrentIndex")

If CurrentIndex < dtReceiver.Rows.Count - 1 Then

            CurrentIndex += 1
            Label8.Text = CurrentIndex + 1
            Session("CurrentIndex") = CurrentIndex
            C1CountryUser.Text = dtReceiver.Rows(CurrentIndex).Item("Country")

End If
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38295453
Your explanation is fine .
 I need these two things to further help you
1.Post screen shot how your processing your functionality with clear caption on those specific images and also what is causing you issue .

2.Also , Just create a sample demo code [not like above with pieces of information]  with  aspx,codebehind and xml files are required  for me to run and face your issue with that code .

Meeran03
0
 

Author Comment

by:vcharles
ID: 38295466
Ok. I will cretae a separate project to isolate this issue and send you all the code.
Thanks.
V.
0
 

Author Comment

by:vcharles
ID: 38296284
Hi,

Below is the link to the sample project with both list box and combo box.

http://speedy.sh/WCpYm/WebApplication13.zip

I also could not figure out hoe to implement the Next and Previous buttons.

Further below is the actual code, incase zýou can not download the project.

1.VBX

Imports System.Xml
Imports System
Imports System.Text
Imports C1.Web.UI.Controls.C1ComboBox
Imports C1.Web.UI.Controls.C1Input
Imports System.IO
Public Class WebForm1
    Inherits System.Web.UI.Page
    Public CurrentIndex As Integer
    Dim dtNSN As DataTable
    Dim dtAmmoType As DataTable
    Dim dtSDeactivation As DataTable
    Public dtTable As DataTable

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

    Protected Sub C1Fuze_SelectedIndexChanged(sender As Object, args As C1.Web.UI.Controls.C1ComboBox.C1ComboBoxEventArgs)

    End Sub

    Protected Sub C1NSN_SelectedIndexChanged(sender As Object, e As EventArgs) Handles C1NSN.SelectedIndexChanged

    End Sub
    Public Function SearchFuze()
        'Declaration XmlDocuments
        Dim xdLink As New Xml.XmlDocument
        Dim xdLinkA As New Xml.XmlDocument
        Dim xdNSN As New Xml.XmlDocument
        Dim xdSDeactivation As New Xml.XmlDocument

        ' load XML documents
        xdLink.Load(Server.MapPath("~/App_Data/LinkSSADB.xml"))
        xdLinkA.Load(Server.MapPath("~/App_Data/LinkA.xml"))
        xdNSN.Load(Server.MapPath("~/App_Data/NSN.xml"))
        xdSDeactivation.Load(Server.MapPath("~/App_Data/SDeactivation.xml"))

        'Declare variables
        Dim Name As String
        Dim NSNID As String
        Dim SDeactivationID As String
        Dim NSNID2 As String
        Dim SDeactivationID2 As String

        dtSDeactivation = New DataTable
        dtSDeactivation.Columns.Add("SDeactivation_ID", GetType(String))
        dtSDeactivation.Columns.Add("SDeactivation", GetType(String))

        dtNSN = New DataTable
        dtNSN.Columns.Add("NSN_ID", GetType(String))
        dtNSN.Columns.Add("NSN", GetType(String))

        dtTable = New DataTable
        dtTable.Columns.Add("LinkID2", GetType(Integer))
        Session("dtTable") = dtTable
       
        Session("dtSDeactivation") = dtSDeactivation
        Session("dtNSN") = dtNSN

        Session("CurrentIndex") = 0
       


        For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/LinkA[Fuze_ID='" & C1Fuze.SelectedItem.Value & "']")
            Link_ID = xnLink.SelectSingleNode("LinkAID").InnerText
            NSNID = xnLink.SelectSingleNode("NSN_ID").InnerText
            For Each xnNSN As Xml.XmlNode In xdNSN.SelectNodes("/Root/NSNTable[contains('," & NSNID & ",', concat(',', NSN_ID, ','))]")
                NSNID2 = xnNSN.SelectSingleNode("NSN_ID").InnerText
                Name = xnNSN.SelectSingleNode("NSN").InnerText

                dtNSN.Rows.Add({NSNID2, Name})

            Next
           
            LinkID2 = xnLink.SelectSingleNode("LinkAID").InnerText
            dtTable.Rows.Add({LinkID2})

            For Each xnLinkA As Xml.XmlNode In xdLinkA.SelectNodes("/Root/LinkA[LinkAID='" & LinkID2 & "']")
               
                SDeactivationID = xnLinkA.SelectSingleNode("SDeactivation_ID").InnerText

                For Each xnSDeactivation As Xml.XmlNode In xdSDeactivation.SelectNodes("/Root/SDeactivationTable[contains('," & SDeactivationID & ",', concat(',', SDeactivation_ID, ','))]")
                    SDeactivationID2 = xnSDeactivation.SelectSingleNode("SDeactivation_ID").InnerText
                    Name = xnSDeactivation.SelectSingleNode("SDeactivation").InnerText

                    dtSDeactivation.Rows.Add({SDeactivationID2, Name})
                    utubeC += Name & ","
                Next

                If utubeC <> "" Then
                    utubeC = utubeC.Substring(0, utubeC.Length - 1) 'To remove last semicolon
                End If
            Next
            MsgBox(utubeC)
        Next
        If dtTable.Rows.Count >= 1 Then

            ViewData()
        End If
    End Function
    Private Sub ViewData()

        Dim SDeactivation As New DataSet
        SDeactivation.ReadXml(Server.MapPath("~/App_Data/SDeactivation.xml"))
        C1SDeactivation.DataSource = SDeactivation.Tables(0)
        C1SDeactivation.DataTextField = "SDeactivation"
        C1SDeactivation.DataValueField = "SDeactivation_ID"
        C1SDeactivation.DataBind()
        C1SDeactivation.ClearSelection()
        If utubeC IsNot Nothing Then
            For i As Integer = 0 To C1SDeactivation.Items.Count - 1
                If utubeC.Split(",").Contains(C1SDeactivation.Items(i).Text) Then
                    C1SDeactivation.Items(i).Selected = True
                    Dim CB As CheckBox = C1SDeactivation.Items(i).FindControl("CheckSDeactivation")
                    CB.Checked = True
                End If
            Next
        End If

        C1NSN.Items.Clear()
        C1NSN.DataSource = dtNSN
        C1NSN.DataTextField = "NSN"
        C1NSN.DataValueField = "NSN_ID"
        C1NSN.DataBind()

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        dtTable = Session("dtTable")
        dtSDeactivation = Session("dtSDeactivation")
        dtNSN = Session("dtNSN")

    End Sub
    Private Sub loadfile()
        If IsPostBack = False Then
            Dim Fuze As New DataSet
            C1Fuze.Items.Clear()
            Fuze.ReadXml(Server.MapPath("~/App_Data/Fuze.xml"))
            C1Fuze.DataSource = Fuze.Tables(0)
            C1Fuze.DataMember = "Fuze"
            C1Fuze.DataTextField = "Fuze"
            C1Fuze.DataValueField = "Fuze_ID"
            C1Fuze.DataBind()

            Dim SDeactivation As New DataSet
            SDeactivation.ReadXml(Server.MapPath("~/App_Data/SDeactivation.xml"))
            C1SDeactivation.DataSource = SDeactivation.Tables(0)
            C1SDeactivation.DataTextField = "SDeactivation"
            C1SDeactivation.DataValueField = "SDeactivation_ID"
            C1SDeactivation.DataBind()
        End If
    End Sub
End Class


ASPX.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication13.WebForm1" %>
<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1ComboBox" tagprefix="cc1" %>
<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1Input" tagprefix="cc2" %>
<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1GridView" tagprefix="cc1" %>
<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1Input" tagprefix="cc3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<script runat="server">
    Sub C1Fuze_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        SearchFuze()
    End Sub
</script>
<body>
    <form id="form1" runat="server">
    <div style="height: 332px">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <cc1:C1ComboBox ID="C1Fuze" runat="server"  
                            DropDownPositioningMode="BottomCenter" Width="180px"
                            MaxLength="35" Text="Enter/Select" AutoComplete="False" AppendDataBoundItems="True"
                            OnSelectedIndexChanged="C1Fuze_SelectedIndexChanged" AutoPostBack="True">
                              </cc1:C1ComboBox>
                              <asp:ListBox ID="C1NSN" runat="server" Width="115px" Height="89px">
                      </asp:ListBox>
                      <cc1:C1ComboBox ID="C1SDeactivation" runat="server" AccessKey=""
                         DropDownPositioningMode="Absolute" HideDropDownListOnBlur="False"
                         SelectionMode="Multiple" Width="328px"  OnClientSelectedIndexChanged="C1SDeactivation_OnClientSelectedIndexChanging"
                         ShowTrigger="False" OpenDropDownOnLoad="True">

                         <ItemsTemplate>
                             <asp:CheckBox ID="CheckSDeactivation" runat="server" />
                             <%# DataBinder.Eval(Container.DataItem, "SDeactivation")%>
                         </ItemsTemplate>
                      </cc1:C1ComboBox>
        <asp:Button ID="Button1" runat="server" Text="Next" />
    </div>
    </form>
</body>
</html>


Thanks,

Victor
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38301431
Using module in asp.net thats a bad coding which may result in  security issues .
Gothrough this article .
http://jbknet.blogspot.in/2005/07/vbnet-modules-in-aspnet-trick-or-treat.html

This will select all checkboxes according to the value of first dropdownlist .

dim utubec As String 'In codebehind
Public Function SearchFuze()
        'Declaration XmlDocuments
        Dim xdLink As New Xml.XmlDocument
        Dim xdLinkA As New Xml.XmlDocument
        Dim xdNSN As New Xml.XmlDocument
        Dim xdSDeactivation As New Xml.XmlDocument

        ' load XML documents
        xdLink.Load(Server.MapPath("~/App_Data/LinkSSADB.xml"))
        xdLinkA.Load(Server.MapPath("~/App_Data/LinkA.xml"))
        xdNSN.Load(Server.MapPath("~/App_Data/NSN.xml"))
        xdSDeactivation.Load(Server.MapPath("~/App_Data/SDeactivation.xml"))

        'Declare variables
        Dim Name As String
        Dim NSNID As String
        Dim SDeactivationID As String
        Dim NSNID2 As String
        Dim SDeactivationID2 As String
        Dim Link_ID As String, LinkID2 As String

        dtSDeactivation = New DataTable
        dtSDeactivation.Columns.Add("SDeactivation_ID", GetType(String))
        dtSDeactivation.Columns.Add("SDeactivation", GetType(String))

        dtNSN = New DataTable
        dtNSN.Columns.Add("NSN_ID", GetType(String))
        dtNSN.Columns.Add("NSN", GetType(String))

        dtTable = New DataTable
        dtTable.Columns.Add("LinkID2", GetType(Integer))
        Session("dtTable") = dtTable

        Session("dtSDeactivation") = dtSDeactivation
        Session("dtNSN") = dtNSN

        Session("CurrentIndex") = 0



        For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/LinkA[Fuze_ID='" & C1Fuze.SelectedItem.Value & "']")
            Link_ID = xnLink.SelectSingleNode("LinkAID").InnerText
            NSNID = xnLink.SelectSingleNode("NSN_ID").InnerText
            For Each xnNSN As Xml.XmlNode In xdNSN.SelectNodes("/Root/NSNTable[contains('," & NSNID & ",', concat(',', NSN_ID, ','))]")
                NSNID2 = xnNSN.SelectSingleNode("NSN_ID").InnerText
                Name = xnNSN.SelectSingleNode("NSN").InnerText

                dtNSN.Rows.Add({NSNID2, Name})

            Next

            LinkID2 = xnLink.SelectSingleNode("LinkAID").InnerText
            dtTable.Rows.Add({LinkID2})

            For Each xnLinkA As Xml.XmlNode In xdLinkA.SelectNodes("/Root/LinkA[LinkAID='" & LinkID2 & "']")

                SDeactivationID = xnLinkA.SelectSingleNode("SDeactivation_ID").InnerText

                For Each xnSDeactivation As Xml.XmlNode In xdSDeactivation.SelectNodes("/Root/SDeactivationTable[contains('," & SDeactivationID & ",', concat(',', SDeactivation_ID, ','))]")
                    SDeactivationID2 = xnSDeactivation.SelectSingleNode("SDeactivation_ID").InnerText
                    Name = xnSDeactivation.SelectSingleNode("SDeactivation").InnerText

                    dtSDeactivation.Rows.Add({SDeactivationID2, Name})
                    'utubec &= Name & ","
                    If utubec = "" Then
                        utubec = Name
                    Else
                        If utubec.Split(",").Contains(Name) = False Then
                            utubec = utubec & "," & Name
                        End If
                    End If
                Next
                'If utubec <> "" Then
                '    utubec = utubec.Substring(0, utubec.Length - 1) 'To remove last semicolon
                'End If
            Next

        Next
        Response.Write("Your utubec is : " & utubec)
        If dtTable.Rows.Count >= 1 Then
            ViewData()
        End If
    End Function

Open in new window



Meeran03
screenShotafterfirstddl.png
0
 

Author Comment

by:vcharles
ID: 38301673
Hi,

Thanks for the advice, I will check out the article,

I will test the code later today and get back to you.

Thanks,

V.
0
 

Author Comment

by:vcharles
ID: 38301685
Can you please look into a solution for displaying one record at a time in the listbox.
Thanks.
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38301889
For single record in listbox.    

 
Private Sub ViewData()
        Dim SDeactivation As New DataSet
        SDeactivation.ReadXml(Server.MapPath("~/App_Data/SDeactivation.xml"))
        C1SDeactivation.DataSource = SDeactivation.Tables(0)
        C1SDeactivation.DataTextField = "SDeactivation"
        C1SDeactivation.DataValueField = "SDeactivation_ID"
        C1SDeactivation.DataBind()
        C1SDeactivation.ClearSelection()
        If utubec IsNot Nothing Then
            For i As Integer = 0 To C1SDeactivation.Items.Count - 1
                If utubec.Split(",").Contains(C1SDeactivation.Items(i).Text) Then
                    C1SDeactivation.Items(i).Selected = True
                    Dim CB As CheckBox = C1SDeactivation.Items(i).FindControl("CheckSDeactivation")
                    CB.Checked = True
                End If
            Next
        End If
        Dim _table As DataTable
        _table = dtNSN.Clone()
        _table.ImportRow(dtNSN.Rows(0))
        C1NSN.DataSource = _table
        C1NSN.DataTextField = "NSN"
        C1NSN.DataValueField = "NSN_ID"
        C1NSN.DataBind()
    End Sub

Open in new window

0
 

Author Comment

by:vcharles
ID: 38302058
Hi,

I replaced the SearchFuze Function with your code but I don't get the same results. I am getting an error message:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

And when I click continue, no rows are selected in the dropdown list.

Any ideas why it is not working?

V.
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38304190
try this application and update the status .

http://speedy.sh/srSYC/xmlUpdate.rar

Meeran03
0
 

Author Comment

by:vcharles
ID: 38304250
Hi,

Can not download file from work, will try it later from home and get back to you.

Thanks,

V.
0
 

Author Comment

by:vcharles
ID: 38304452
Hi again,

Sorry for being a pain, but can you please send me the file in .zip format. I recall having difficulties dowloading .rar files.

Thanks,

Victor
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38304476
What it does .
   1.Select multiple checkboxes
   2.Display only one value in listbox

http://speedy.sh/6bNWN/xmlUpdate.zip
0
 

Author Comment

by:vcharles
ID: 38304518
Thanks, I really appreciate your Help.
Victor
0
 

Author Comment

by:vcharles
ID: 38307015
Hi,

I'm afraid it is not working properly for me.

I used the xml files listed below, when I select L112A1, since its ID is 1 I should see the following data in my list box

1304-00-023-1111
1304-00-023-2222

and when i click on the Next button, I should see

1304-00-023-3333
1304-00-023-4444

However I am only getting 1304-00-023-1111 and pressing Next does not move me to the next record.

Can you please Help me fix this problem.

LinkSSADB.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <LinkA>
    <LinkAID>0</LinkAID>
    <Fuze_ID>0</Fuze_ID>
    <NSN_ID>0</NSN_ID>
  </LinkA>
  <LinkA>
    <LinkAID>1</LinkAID>
    <Fuze_ID>1</Fuze_ID>
    <NSN_ID>1,2</NSN_ID>
  </LinkA>
  <LinkA>
    <LinkAID>2</LinkAID>
    <Fuze_ID>1</Fuze_ID>
    <NSN_ID>3,4</NSN_ID>
  </LinkA>
</Root>

NSN.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <NSNTable>
    <NSN_ID>0</NSN_ID>
    <NSN>NA</NSN>
  </NSNTable>
  <NSNTable>
    <NSN_ID>1</NSN_ID>
    <NSN>1304-00-023-1111</NSN>
  </NSNTable>
  <NSNTable>
    <NSN_ID>2</NSN_ID>
    <NSN>1304-00-023-2222</NSN>
  </NSNTable>
   <NSNTable>
    <NSN_ID>3</NSN_ID>
    <NSN>1304-00-023-3333</NSN>
  </NSNTable>
 <NSNTable>
    <NSN_ID>4</NSN_ID>
    <NSN>1304-00-023-4444</NSN>
  </NSNTable>
</Root>


Victor
0
 

Author Comment

by:vcharles
ID: 38307054
Hi,

It is also not working for the combobox when I select L112A1. When I use the xml files below, the correct checkboxes are checked for the first record (LinkAID = 1)  but when I click the Next button it does not check the rows for LinkAID = 2.

How do I move to the next record? I tried the code below, but it does not work.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        dtTable = Session("dtTable")
        dtSDeactivation = Session("dtSDeactivation")
        dtNSN = Session("dtNSN")
        'Viewdata()
        ' Dim SDeactivation As New DataSet
        'SDeactivation.ReadXml(Server.MapPath("~/App_Data/SDeactivation.xml"))
        C1SDeactivation.DataSource = dtSDeactivation
        C1SDeactivation.DataTextField = "SDeactivation"
        C1SDeactivation.DataValueField = "SDeactivation_ID"
        C1SDeactivation.DataBind()
        C1SDeactivation.ClearSelection()
        If utubec IsNot Nothing Then
            For i As Integer = 0 To C1SDeactivation.Items.Count - 1
                If utubec.Split(",").Contains(C1SDeactivation.Items(i).Text) Then
                    C1SDeactivation.Items(i).Selected = True
                    Dim CB As CheckBox = C1SDeactivation.Items(i).FindControl("CheckSDeactivation")
                    CB.Checked = True
                End If
            Next
        End If

    End Sub

LinkA.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <LinkA>
    <LinkAID>0</LinkAID>
    <SDeactivation_ID>NA</SDeactivation_ID>
  </LinkA>
  <LinkA>
    <LinkAID>1</LinkAID>
    <SDeactivation_ID>0,1,2</SDeactivation_ID>
  </LinkA>
  <LinkA>
    <LinkAID>2</LinkAID>
    <SDeactivation_ID>1,2</SDeactivation_ID>
  </LinkA>
</Root>

Sdeactivation.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <SDeactivationTable>
    <SDeactivation_ID>-1</SDeactivation_ID>
    <SDeactivation>NA</SDeactivation>
    <SDeactivationAbbrev>NA</SDeactivationAbbrev>
  </SDeactivationTable>
  <SDeactivationTable>
    <SDeactivation_ID>0</SDeactivation_ID>
    <SDeactivation>Yes</SDeactivation>
    <SDeactivationAbbrev>Y</SDeactivationAbbrev>
  </SDeactivationTable>
  <SDeactivationTable>
    <SDeactivation_ID>1</SDeactivation_ID>
    <SDeactivation>NO</SDeactivation>
    <SDeactivationAbbrev>N</SDeactivationAbbrev>
  </SDeactivationTable>
  <SDeactivationTable>
    <SDeactivation_ID>2</SDeactivation_ID>
    <SDeactivation>Never</SDeactivation>
    <SDeactivationAbbrev>NV</SDeactivationAbbrev>
  </SDeactivationTable>
</Root>
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307109
i never did any code for next action as you got so many other issues on your code which is to be refactored , now i will work on this issue ie
On next action :
  1.LinkAID will be 2
  2.Listbox will hold for linkaid 2
  3.2nd dropdown list will select all LinkAID = 2

 i hope your looking for this  right ?
Meeran03
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307118
kindly update all the xml files , to replace in my app_code directory. Not sure whether am working on correct files.
0
 
LVL 18

Accepted Solution

by:
Rajar Ahmed earned 2000 total points
ID: 38307236
try this, with next functionality.

http://www.speedyshare.com/dXM69/xmlUpdate.zip


Meeran03
0
 

Author Comment

by:vcharles
ID: 38307345
Hi,

Thanks, It is working great!

I tried the code below to move to Previous but it doesn't work. What is the proper code?
without hard codind the value of the rows? What is the proper code to move to the First and Last  record?

Thanks.

Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
        dtMaster = Session("dtMaster")
        dtKeyMaster = Session("dtKeyMaster")
        Dim rowId As Integer = Session("currentIndex") - 1
        ViewData(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)((CurrentIndex) - 1))
    End Sub
0
 

Author Comment

by:vcharles
ID: 38307398
Hi,

I noticed the code below, pronlem is, some of my controls have will have much more than two rows, is there a way not to hard code the rows?



If dtMaster.Rows.Count >= 1 Then
            ViewData(dtKeyMaster.Rows(0)(1), dtKeyMaster.Rows(0)(2))
        End If

Victor
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307411
Here Previous and next code .
   <asp:Button ID="btnPrev" OnClick="btnPrev_Click" runat="server" Text="PreVious"  style="position:absolute;top:350px;left:50px"/>

Open in new window

'Previous Action
Protected Sub btnPrev_Click(sender As Object, e As EventArgs)
        dtMaster = Session("dtMaster")
        dtKeyMaster = Session("dtKeyMaster")
        Dim rowId As Integer
        If Session("currentIndex") >= 1 Then
            rowId = Session("currentIndex") - 1
        Else
            rowId = 0
        End If
        ViewData(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
        Session("currentIndex") = rowId
    End Sub
'Next Action
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        dtMaster = Session("dtMaster")
        dtKeyMaster = Session("dtKeyMaster")
        Dim rowId As Integer = Session("currentIndex") + 1
        ViewData(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
        Session("currentIndex") = rowId
    End Sub

Open in new window


where did u find Hardcoding .?  i guess its all dynamic values . according to selection of button.
First & last are out of scope of this question .

Meeran03
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307414
I noticed the code below, pronlem is, some of my controls have will have much more than two rows, is there a way not to hard code the rows?

Sorry , the data's which you given before was like that . You can post new question for data change i may work on that or other experts too  with the updated code .

Meeran03
0
 

Author Comment

by:vcharles
ID: 38307539
I thought the code below was for the first two rows.

If dtMaster.Rows.Count >= 1 Then
            ViewData(dtKeyMaster.Rows(0)(1), dtKeyMaster.Rows(0)(2))
        End If

I am trying to integrate your code in my project, noticed ViewData() no longer works, will try to create a separate one using your approach to work with the controls with multiple values.

Thanks again.

V.
0
 

Author Comment

by:vcharles
ID: 38307640
Hi,

I am trying to use your code in my project, but I receive the following error.

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

Any ideas what is causing this error?

V.
Replaced SearchFuze with SearchFuze1 and ViewData with ViewDataA

code:

Public Function SearchFuze1()
        MsgBox("GGGGGGGGGG")
        'Declaration XmlDocuments
        Dim xdLink As New Xml.XmlDocument
        Dim xdLinkA As New Xml.XmlDocument
        Dim xdNSN As New Xml.XmlDocument
        Dim xdSDeactivation As New Xml.XmlDocument
        ' load XML documents
        xdLink.Load(Server.MapPath("~/App_Data/LinkSSADB.xml"))
        xdLinkA.Load(Server.MapPath("~/App_Data/LinkA.xml"))
        xdNSN.Load(Server.MapPath("~/App_Data/NSN.xml"))
        xdSDeactivation.Load(Server.MapPath("~/App_Data/SDeactivation.xml"))
        'Declare variables
        Dim Name As String
        Dim NSNID As String
        Dim fuze_Nsn_id As String
        Dim LinkAID As String
        Dim SDeactivation_ID As String, SDeactivation As String
        Dim SDeactivationID As String
        Dim NSNID2 As String
        Dim SDeactivationID2 As String
        Dim Link_ID As String, LinkID2 As String
        Dim utubec As String
        dtMaster = New DataTable
        dtMaster.Columns.Add("FUZE_NSN_ID", GetType(String))
        dtMaster.Columns.Add("LinkAID", GetType(String))
        dtMaster.Columns.Add("NSN_ID", GetType(String))
        dtMaster.Columns.Add("NSN", GetType(String))
        dtMaster.Columns.Add("SDeactivation_ID", GetType(String))
        dtMaster.Columns.Add("SDeactivation", GetType(String))
        dtKeyMaster = New DataTable
        dtKeyMaster.Columns.Add("rowId", GetType(String))
        dtKeyMaster.Columns.Add("keyLinkAid", GetType(String))
        dtKeyMaster.Columns.Add("keyNsn", GetType(String))
        Dim rowIndex As Integer = 1
        '    C1Fuze.SelectedItem.Value = 1
        For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/LinkA[Fuze_ID='" & C1Fuze.SelectedItem.Value & "']") 'linkssadb.xml
            'For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/LinkA[Fuze_ID='1']") 'linkssadb.xml
            Link_ID = xnLink.SelectSingleNode("LinkAID").InnerText
            NSNID = xnLink.SelectSingleNode("NSN_ID").InnerText
            fuze_Nsn_id = NSNID
            LinkAID = Link_ID
            View2.Visible = True
            'List Box Load With matching fuze id in linkssadb.xml - Starts
            For Each xnNSN As Xml.XmlNode In xdNSN.SelectNodes("/Root/NSNTable[contains('," & NSNID & ",', concat(',', NSN_ID, ','))]") 'NSN.xml
                NSNID2 = xnNSN.SelectSingleNode("NSN_ID").InnerText
                Name = xnNSN.SelectSingleNode("NSN").InnerText
                dtMaster.Rows.Add({fuze_Nsn_id, LinkAID, NSNID2, Name})
            Next
            'List Box Load With matching fuze id in linkssadb.xml - Ends
            LinkID2 = xnLink.SelectSingleNode("LinkAID").InnerText 'linkssadb.xml
            Session("currentIndex") = 0
            For Each xnLinkA As Xml.XmlNode In xdLinkA.SelectNodes("/Root/LinkA[LinkAID='" & LinkID2 & "']") 'LinkA.xml
                SDeactivationID = xnLinkA.SelectSingleNode("SDeactivation_ID").InnerText
                For Each xnSDeactivation As Xml.XmlNode In xdSDeactivation.SelectNodes("/Root/SDeactivationTable[contains('," & SDeactivationID & ",', concat(',', SDeactivation_ID, ','))]") 'xdSDeactivation.xml
                    Name = xnSDeactivation.SelectSingleNode("SDeactivation").InnerText
                    If utubec = "" Then
                        utubec = Name
                    Else
                        If utubec.Split(",").Contains(Name) = False Then
                            utubec = utubec & "," & Name
                        End If
                    End If
                Next
            Next
            For Each row In dtMaster.Select("LinkAID = " & LinkID2)
                row("SDeactivation") = utubec
            Next
            dtMaster.AcceptChanges()
            utubec = ""
            dtKeyMaster.Rows.Add({rowIndex, LinkAID, fuze_Nsn_id})
            rowIndex += 1
        Next
        Response.Write("Your utubec is : " & utubec)
        Session("dtMaster") = dtMaster
        Session("dtKeyMaster") = dtKeyMaster
        If dtMaster.Rows.Count >= 1 Then
            ViewDataA(dtKeyMaster.Rows(0)(1), dtKeyMaster.Rows(0)(2))
        End If
    End Function
    Private Sub ViewDataA(ByVal keyLinkAid As String, ByVal keyNsn As String)
        Dim utubec As String = ""
        For Each row In dtMaster.Select("LinkAID = " & keyLinkAid & " and SDeactivation <> ''")
            utubec = row("SDeactivation")
        Next
        Dim SDeactivation As New DataSet
        SDeactivation.ReadXml(Server.MapPath("~/App_Data/SDeactivation.xml"))
        C1SDeactivation.DataSource = SDeactivation.Tables(0)
        C1SDeactivation.DataTextField = "SDeactivation"
        C1SDeactivation.DataValueField = "SDeactivation_ID"
        C1SDeactivation.DataBind()
        C1SDeactivation.ClearSelection()
        For i As Integer = 0 To C1SDeactivation.Items.Count - 1
            If utubec.Split(",").Contains(C1SDeactivation.Items(i).Text) Then
                C1SDeactivation.Items(i).Selected = True
                Dim CB As CheckBox = C1SDeactivation.Items(i).FindControl("CheckSDeactivation")
                CB.Checked = True
            End If
        Next
        Dim _table As DataView = dtMaster.DefaultView
        _table.RowFilter = "NSN_ID in (" & keyNsn & ")"
        C1NSN.DataSource = _table
        C1NSN.DataTextField = "NSN"
        C1NSN.DataValueField = "NSN_ID"
        C1NSN.DataBind()
     
    End Sub

 Private Sub ViewDataA(ByVal keyLinkAid As String, ByVal keyNsn As String)
        Dim utubec As String = ""
        For Each row In dtMaster.Select("LinkAID = " & keyLinkAid & " and SDeactivation <> ''")
            utubec = row("SDeactivation")
        Next
        Dim SDeactivation As New DataSet
        SDeactivation.ReadXml(Server.MapPath("~/App_Data/SDeactivation.xml"))
        C1SDeactivation.DataSource = SDeactivation.Tables(0)
        C1SDeactivation.DataTextField = "SDeactivation"
        C1SDeactivation.DataValueField = "SDeactivation_ID"
        C1SDeactivation.DataBind()
        C1SDeactivation.ClearSelection()
        For i As Integer = 0 To C1SDeactivation.Items.Count - 1
            If utubec.Split(",").Contains(C1SDeactivation.Items(i).Text) Then
                C1SDeactivation.Items(i).Selected = True
                Dim CB As CheckBox = C1SDeactivation.Items(i).FindControl("CheckSDeactivation")
                CB.Checked = True
            End If
        Next
        Dim _table As DataView = dtMaster.DefaultView
        _table.RowFilter = "NSN_ID in (" & keyNsn & ")"
        C1NSN.DataSource = _table
        C1NSN.DataTextField = "NSN"
        C1NSN.DataValueField = "NSN_ID"
        C1NSN.DataBind()
     
    End Sub
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307652
It seems your using update panel . response statement will not work while async postback.
'Response.Write("Your utubec is : " & utubec)
0
 

Author Comment

by:vcharles
ID: 38307772
I removed Response.Write to remove the error, but when I select L112A1 I see data from both records where Fuze_ID = 1 in my LinkSSADB file, can you please take a look at the code I sent on my previous post, can't figure out what went wrong.
Thanks.
V.
0
 

Author Comment

by:vcharles
ID: 38307821
Hi,

It works for the combobox but as mentioned not I stil see multiple records for ID - 1 in the C1NSN listbox control. Also noticed when I set three records with Fuze_ID = 1 in LinkSSADB.xml, I am only able to move the the second record, I think it is due to the following code:
If dtMaster.Rows.Count >= 1 Then
            ViewDataA(dtKeyMaster.Rows(0)(1), dtKeyMaster.Rows(0)(2))
        End If

Is there a way to use Row(0)(i) where I = recordcount?

Thanks.

V.
0
 

Author Comment

by:vcharles
ID: 38307822
I just tried ViewDataA(dtKeyMaster.Rows(0)(1), dtKeyMaster.Rows(0)(2), dtKeyMaster.Rows(0)(3)), to view the third record, but getting "too many parameters" error message.
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307830
Execept  hiding this 'View2.Visible = True i dint changed anything and it was working good .

I see data from both records where Fuze_ID = 1 in my LinkSSADB file

Not sure what this thing is , i have given you the next previous functionality with the xml files you have given  the issues your facing because of different data's . Sorry, i cant answer them all in a single question itself  i showed you the direction which you can follow from now on or post a new question . Please dont iterate question on this thread its seems like you are never going to end this conversation .  

Meeran03
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307845
hi victor,
   
  All the question your are asking now are new requirement or behaviour change due to different data change which was not given at the time when you submitted the sample application to me . So please dont be offended.

Regards
Meeran03
0
 

Author Comment

by:vcharles
ID: 38307853
OK. I will look more into it, and post another question if I can not find a solution, it should work, just need to spend more time on it to see what went wrong.

Thanks.

Victor
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38307859
Good luck . :)


Meeran03
0
 

Author Comment

by:vcharles
ID: 38307881
Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question