?
Solved

getting repeated column field..in the table..??

Posted on 2009-04-22
7
Medium Priority
?
321 Views
Last Modified: 2013-11-07
Need to fill the tr one after the other ,

These are my data's in the two tables...
tblcou
cid  country
3     Australia
4     India    

tblstat
Sid   state               cid(foreignkey of tablecountry )
2       Perth             3
5       sydney          3
6       delhi              4
7       bombay         4

These data's are filled  like this ...
Australia                               Australia
         Perth                                      Sydney
India                                  India
       Delhi                                Bombay

But i want to fill in this way..
Australia                                India
         Perth                                    Bombay
         Sydney                                    Delhi
 
Please Suggest..
  so that  i dont get get repeated coutry in a row..Please suggest...
<body>
    <form id="form1" runat="server">
    <div>
    <%
         Dim Cnt As Integer
          cmd = New SqlCommand("select country.tblcou,state.tblstat from tblstat inner join  tblcou ON tblcou.cid=tblstat.cid", con)
        con.open()
        myDataReader = cmd.ExecuteReader()
        Cnt = 0
        Dim str As String = 0
        Response.Write("<table>")
        While (myDataReader.Read())
            If Cnt Mod 2 = 0 Then
                Response.Write("<tr>")
            End If
            Response.Write("<td width=""10%""> "& myDataReader.Item(0) & "</a>  " & myDataReader.Item(1) & " </td><td></td>")%>                         
            <%If Cnt Mod 2 <> 0 Then
                Response.Write("</tr>")
            End If
                Cnt = Cnt + 1
            End While
         Response.Write("</table>")
        %>
        </div>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:Rajar Ahmed
  • 4
  • 2
7 Comments
 
LVL 10

Assisted Solution

by:Christian de Bellefeuille
Christian de Bellefeuille earned 400 total points
ID: 24207025
Something like this?
<body>
    <form id="form1" runat="server">
    <div>
    <%
         Dim Cnt As Integer
         Dim sLast as string
 
          cmd = New SqlCommand("select country.tblcou,state.tblstat from tblstat inner join  tblcou ON tblcou.cid=tblstat.cid", con)
        con.open()
        myDataReader = cmd.ExecuteReader()
        Cnt = 0
        Dim str As String = 0
        Response.Write("<table>")
        While (myDataReader.Read())
            If Cnt Mod 2 = 0 Then
                Response.Write("<tr>")
            End If
 
            if sLast <> myDataReader.Item(0) then
                 Response.Write("<td width=""10%""> "& myDataReader.Item(0) & "</a>  <li>" & myDataReader.Item(1) & "</li></td><td></td>")
                 sLast = myDataReader.Item(0)
            else
                 Response.Write("<td width=""10%""> <li>"& myDataReader.Item(1) & "</li></td><td></td>")
            end if
%>                         
            <%If Cnt Mod 2 <> 0 Then
                Response.Write("</tr>")
            End If
                Cnt = Cnt + 1
            End While
         Response.Write("</table>")
        %>
        </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 2

Expert Comment

by:neo00000110
ID: 24207064
hi,

i didn't have time to run this, but you should get the idea. You need to store and test the country field and if it is the same as the previous row you don't write the country just the state. Also you need to split them into seperate table cells somehow for your format so in this example i showed you with two table cells with tables inside.

hope it gets you in the right direction.
<div>
    <%
         Dim Cnt As Integer
          cmd = New SqlCommand("select country.tblcou,state.tblstat from tblstat inner join  tblcou ON tblcou.cid=tblstat.cid", con)
        con.open()
        myDataReader = cmd.ExecuteReader()
        Cnt = 0
        Dim str As String = 0
	dim strCou as string = ""
 
        Response.Write("<table>")
	response.write("<tr>")
	response.write("<td>")
	
        While (myDataReader.Read())
	   if myDataReader.Item(0) <> strcou then 
		if strcou <> "" then response.write("</table></td><td>")
	        Response.Write("<table><tr><tD **plus all the javascript**>" & mydatareader.item(0) & "</tD></tr>")
		
		strcou = mydatareader.item(0)		
           End If
       
	  Response.Write("<tr><td width=""10%""> <div id=""div" & Cnt & """ class=""div4"">" & myDataReader.Item(1) & " </div></td><td></td></tR>")                        
            
	end while
	
	response.write("</table>")
	response.write("<td>")
	response.write("</tR>")
         Response.Write("</table>")
        %>
</div>

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24211768
hi cdebel ,

i need only two columns for eg,

cid  country
3     Australia
4     India    
5     America
6     England
   
tblstat
Sid   state               cid
2       Perth             3
5       sydney          3
6       delhi              4
7       bombay         4
6        Newyork       5
7        washington   5
8        london           6
9        Manchester    6

Its filling like this , but  i need only two columns..
Australia           India             america                          England
         Perth         Bombay          newyork                        london
         Sydney       Delhi             washington                        manchester

i mean like this
Australia           India            
         Perth         Bombay        
         Sydney       Delhi            

america              England
 newyork                 london
 washington              manchester

Please suggest.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24211777
previous comment is posted for neo00000110 . srry by mistakenly written as cdebel...


0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24211806
hi, this is for cdebel...

In this case , i get only two columns only , but its binding only for first state, and second state is being printed in other column...

i mean Like this,,

cid  country
3     Australia
4     India    
5    america
tblstat
Sid   state               cid(foreignkey of tablecountry )
2       Perth             3
5       sydney          3
6       delhi              4
7       bombay         4
8       calcutta         4
6        Newyork       5
7        washington   5
 
Output ....

australia                       sydney
perth

India                             bombay
delhi

calcutta                        america
                                     newyork

washington


.....
0
 
LVL 2

Accepted Solution

by:
neo00000110 earned 1600 total points
ID: 24213034
ok in this case you just need to run a counter for 2 like you did originally for your columns, but instead for rows. something like below.
<div>
    <%
         Dim Cnt As Integer
          cmd = New SqlCommand("select country.tblcou,state.tblstat from tblstat inner join  tblcou ON tblcou.cid=tblstat.cid", con)
        con.open()
        myDataReader = cmd.ExecuteReader()
        Cnt = 0
        Dim str As String = 0
        dim strCou as string = ""
 
	dim intCount as int = 0
 
        Response.Write("<table>")
        response.write("<tr>")
        response.write("<td>")
        
        While (myDataReader.Read())
           if myDataReader.Item(0) <> strcou then 
	
		if intcount = 2 then 
			response.write("</table></td></tr><tr><td>")
			intcount = 0
			strcou =""
		end if                
 
		if strcou <> "" then response.write("</table></td><td>")
                Response.Write("<table><tr><tD **plus all the javascript**>" & mydatareader.item(0) & "</tD></tr>")
                
                strcou = mydatareader.item(0)           
		
		intcount +=1
 
           End If
       
          Response.Write("<tr><td width=""10%""> <div id=""div" & Cnt & """ class=""div4"">" & myDataReader.Item(1) & " </div></td><td></td></tR>")                        
            
        end while
        
        response.write("</table>")
        response.write("<td>")
        response.write("</tR>")
         Response.Write("</table>")
        %>
</div>

Open in new window

0
 
LVL 18

Author Closing Comment

by:Rajar Ahmed
ID: 31573374
Thanks a million......
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

807 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