Datagrid在文本框上显示用户名时出现问题 [英] Datagrid Issue while displaying the usernames on textboxes

查看:69
本文介绍了Datagrid在文本框上显示用户名时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在努力研究数据网格。我的任务是显示文本框中存在于数据网格的一列中的所有用户名。所以textbox id是数据网格中的每一行。我设法通过选择firstnamelastname,firstname.lastname和initialfirstnamelastname来显示用户名



示例:FirstName:Kevin

姓氏:Smith



所以我有diplayed kevinsmith(firstnamelastname),kevin.smith(firstname.lastname)和k.smith(initialfirstnamelastname),但问题是名字和姓氏超过一个员工可以是一样的。因此,如果多个emloyee具有相同的firstnamelastname或initialfirstnamelastname,则文本框将具有相同的用户名。我想要的是显示具有连续数字的重复文本框用户名。



示例:如果2个或更多员工拥有相同的名字和姓氏Kevin(名字)和Smith(姓氏)



数据网格中的第一个存在可以显示普通用户名kevinsmith(firstnamelastname)



但是在数据网格的第二行中,文本框不应该相同价值像凯文斯密斯。而不是kevinsmith它必须显示kevinsmith1,kevinsmith2等增加1.







任何人都可以帮我解决上述问题。真的很感激,对我来说会很有帮助

解决方案

首先,请阅读我的评论。



如果您的数据来自数据库,您可以使用以下查询:

  DECLARE   @ myUsers  (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 < span class =code-key单词> INTO @ myUsers (UFName,ULName)
VALUES (< span class =code-string>' Maciej'' Los'
INSERT INTO @ myUsers (UFName,ULName)
VALUES ' Maciej'' Los'

SELECT SRC。[UFName],SRC。[ULName], CONVERT NVARCHAR 100 ),SRC。[Nick] + CASE [UserID] WHEN 1 然后 ' ' 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 [尼克]
FROM @ myUsers
AS SRC





结果:

 [UFName] [ ULName] [尼克] 
Kevin Smith KSmith
Kevin Smith KSmith1
Kevin Smith KSmith2
Kevin Smith KSmith3
Maciej Los MLos
Maciej Los MLos1


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

解决方案

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


这篇关于Datagrid在文本框上显示用户名时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆