Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Maciej Los 3-Mar-13 7:28am    
Does your data coming from database?

1 solution

First of all, read my comment.

If your data coming from database, you can use query like that:
SQL
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900