Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET4
Hello Everyone. I am trying to work on the data grid. My task is to display all the username in the textbox which is present in one column of a data grid. so textbox id is each row in the data grid. I have managed to display the user name by selecting firstnamelastname, firstname.lastname and initialfirstnamelastname
 
Example: FirstName: Kevin
LastName: Smith

so I have diplayed kevinsmith(firstnamelastname), kevin.smith(firstname.lastname) and k.smith(initialfirstnamelastname) but the problem is firstname and last name of more than one employee can be same. so the text box will have the same user names if more than one emloyee have the same firstnamelastname or initialfirstnamelastname. What I want is to display the duplicate textbox user name with the consecutive numbers.
 
Example: If 2 or more employee have same firstname and lastname Kevin(firstname) and Smith(lastname)
 
the first present in the datagrid can display the normal user name kevinsmith (firstnamelastname)
 
but in second row of the datagrid the text box should not have the same value like kevinsmith. Instead of kevinsmith it has to display kevinsmith1, kevinsmith2 and so on which is increasing by 1.
 

 
Could any one please help me to sort out the above issue. Would really appreciate and would be a great help for me
Posted 3-Mar-13 1:31am
Comments
Maciej Los at 3-Mar-13 7:28am
   
Does your data coming from database?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First of all, read my comment.
 
If your data coming from database, you can use query like that:
DECLARE @myUsers TABLE(UFName NVARCHAR(30), ULName NVARCHAR(50))
 
INSERT INTO @myUsers (UFName, ULName)
VALUES('Kevin','Smith')
INSERT INTO @myUsers (UFName, ULName)
VALUES('Kevin','Smith')
INSERT INTO @myUsers (UFName, ULName)
VALUES('Kevin','Smith')
INSERT INTO @myUsers (UFName, ULName)
VALUES('Kevin','Smith')
INSERT INTO @myUsers (UFName, ULName)
VALUES('Maciej','Los')
INSERT INTO @myUsers (UFName, ULName)
VALUES('Maciej','Los')
 
SELECT  SRC.[UFName], SRC.[ULName], CONVERT(NVARCHAR(100), SRC.[Nick] + CASE [UserID] WHEN 1 THEN '' ELSE CONVERT(NVARCHAR(10), [UserID]-1) END) AS [UserNick]
FROM(
	SELECT ROW_NUMBER() OVER(PARTITION BY [UFName], [ULName] ORDER BY [UFName], [ULName]) AS [UserID], [UFName], [ULName], SUBSTRING([UFName],1,1) + [ULName] AS [Nick]
	FROM @myUsers
)AS SRC
 
Results:
[UFName]	[ULName]	[Nick]
Kevin		Smith		KSmith
Kevin		Smith		KSmith1
Kevin		Smith		KSmith2
Kevin		Smith		KSmith3
Maciej		Los		MLos
Maciej		Los		MLos1
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 265
1 Sergey Alexandrovich Kryukov 202
2 George Jonsson 185
3 King Fisher 185
4 CPallini 155
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 3 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100