Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 24th, 2006, 04:08 PM
Authorized User
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to KamalRaturi Send a message via Yahoo to KamalRaturi
Default Binding Gridview with variable number of records

hi ,
I have a variable string e.g. ("25,3,45,32") which is stored in a field of Table.The String is of variable length, it could be "1,4,22" or "456,54,32,21,56,89,57" in datbase(SQL 2005)
The problem is that I have to access the records from anathor table where the comma separated values of string is a field (i.e ID)

Table1 Table2 Result(I Want)
------------ ------------ ----------------------
id Name strID Name
------------ ------------ -----------------------
1 a 2,3,11 b,c,f
2 b 2 b
3 c 1,3,6,9,11,31 a,c,d,e,f,g
6 d 1,3,32 ---and so on---
9 e 11
11 f 6,9
31 g 1
32 h 31,32

I want a single Function or Procedure that will access the values strID from begining to end of Table2 and join the records in Table1
with the IDs that are in the String.When all Records will be accessed by all rows of Table2 from Table1, then the Resultent Data has to be bind with DataBound Control(Gridview)
 if you know How to do this ,please tell me how .
Old August 24th, 2006, 06:48 PM
Friend of Wrox
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts

The problem is you have data stored like that. What you should do is normalize the data.

You said those are ID's to the primary key to another table. So what you have then is either a one-to-many or a many-to-many relationship.

You need to normalize this data and then you won't even have the problem because you will pull the correct number of rows that you can bind to a gridview in the first place. I know how to do it but describing it here in words is very difficult.

If you can not, or won't normalize the data, then you can use the field of comma separated FK ID's in an SQL Query using the "IN" clause. Do something like this:

SELECT CommaSeparatedField
FROM TableWithCommaField
WHERE [whatever constraints you want here]

Then take that comma separated field you got from the above query and do:

FROM OtherTable
WHERE OtherTableId IN ( [field of comma separated values here] )

You know, and of course implement that however, with SQL statements you build as strings or with stored procedures or whatever you want.

Hope that helps.


Neil Timmerman
Veris Consulting
Old August 26th, 2006, 02:05 PM
Authorized User
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to KamalRaturi Send a message via Yahoo to KamalRaturi

hi thenOSEKnows,
as u told me , i used Normallization for the solution ,
and simply it works.

Thanks friend!

Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding with Arraylist myself.panku .NET Framework 2.0 2 November 5th, 2008 05:52 AM
Binding GridView to ObjectDataSource which... rsearing ASP.NET 2.0 Professional 15 July 9th, 2008 01:44 AM
Gridview problem in Binding ndramkumar ASP.NET 2.0 Professional 1 September 2nd, 2007 11:45 PM
Gridview number of records display jodojan ASP.NET 2.0 Basics 3 April 14th, 2007 05:29 AM
Binding fields on a gridview aldwinenriquez ASP.NET 2.0 Professional 0 June 1st, 2006 07:50 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.