• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

The value of the first 2 columns for all the rows are the same. how can i use asp.net to display the info look something like this

i called a sql query to a view and return the records below.

PID     Description     PInfoName     pInfoValue
888     Portable PC     Model ID     p909
888     Portable PC     CPU          P4 3.4G
888     Portable PC     Memory          2G RAM

The value of the first 2 columns for all the rows are the same.  how can i use asp.net to display the info look something like this
General Info:
PID     Description
888     Portable PC

Product details info:
Model ID     p909
CPU            P4 3.4G
Memory      2G RAM    
0
musclejack
Asked:
musclejack
  • 3
1 Solution
 
arif_eqbalCommented:
You are taking the case of only one item
i.e. when PID=888
what if there are 6 records 3 for PID=888 as you have shown
and three for PID=999

Then how would you like to show???
One way is you canhave the PID and Description in one dataGrid and the rest info on the other datagrid
When user selects a row in top Datagrid the bottom one gets populated with details of the particular PID

OR

you can have a Combobox and a Dtatgrid

0
 
musclejackAuthor Commented:
can u give me an simple example?  thx
0
 
arif_eqbalCommented:
OK here goes...

What I have done is Add One ComboBox to a Form and Named it CmbPID
And Added a dataGrid called DetailsdataGrid

Then, At Form level declare

    Dim DTDetails As DataTable
    Dim ConStr As String="Provider=..... YOUR CONNECTION STRING ...."

    'On Form Load Call the Function FillData
    Private Sub FrmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillData()
    End Sub

  'FillData Loads the PID and the Description in a Combo Box. It loads all the unique PIDs
    Private Sub FillData()
        Dim DR As OleDbDataReader
        Dim Cn As OleDbConnection = New OleDbConnection(ConStr)
        Dim Cmd As OleDbCommand = New OleDbCommand("Select Distinct PID, Description From Mytable", Cn) 'Remember the keyword DISTINCT
        'The Qurery will change based on the exact table and Column Names
        Cn.Open()
        DR = Cmd.ExecuteReader
        Do While DR.Read
            Me.CmbPID.Items.Add(DR(0) & " " & Dr(1))
        Loop
        DR.Close()
        Cn.Close()
    End Sub

   'Now Whenever you select a PID from the Combo, This event is fired. here we fill the DataGrid with the
'Details of that particular PID which was selected in the Combo
    Private Sub CmbPID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbPID.SelectedIndexChanged
        DTDetails = New DataTable
        Dim DA As OleDbDataAdapter = New OleDbDataAdapter("Select PInfoName,PInfoValue From Mytable Where PID='" & Me.CmbPID.Text & "'", ConStr)
        DA.Fill(DTDetails)
        Me.DetailsDataGrid.DataSource = DTDetails
    End Sub


That's it
I have just assumed a Table named MyTable with 4 columns as mentioned by you
0
 
arif_eqbalCommented:
A small background what this whole thing will do

We'll have a form with one Combo Box and One DataGrid
ComboBox will have All PIDs and Desctiption eg
888 Portable PC    
999 LapTop

Then whenever you select an Item from the Combo Say 888, the dataGrid will show all the details of it like


Model ID     p909
CPU            P4 3.4G
Memory      2G RAM  

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now