有问题在SelectedIndexChanged上从GridView显示DropDownList的值! [英] Having problem to show the value on DropDownList from GridView on SelectedIndexChanged!

查看:70
本文介绍了有问题在SelectedIndexChanged上从GridView显示DropDownList的值!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在填充数据库表中的下拉列表。我将该表的ID作为值,并将两列的组合作为文本,代码如下:

I'm populating a dropdown list from database table. I' m taking as a value the ID of that table and as a text the combination of two columns, the code is as following:

SELECT PERSON.ID_Person, (PERSON.FName+ ' ' + PERSON.LName)as FirstLastName FROM PERSON





好​​的,这很好。

当我选择行到SelectedIndexChanged时问题是代码。

所有其他列工作正常,除了我连接fname和lname的列。

网格视图gvPerson正在以与DropDownList相同的方式读取这些列,它也连接这两列。

选择行时C#ASP.NET中的代码如下:/ b $ b



Ok this works good.
The problem is to the code when I select the row to the SelectedIndexChanged.
All other columns work fine except the column that I concatenated the fname and lname.
The Grid View gvPerson is reading those columns in the same manner as the DropDownList,it concatenates those two columns as well.
The code in C# ASP.NET when selecting a row is as following

ddListPerson.SelectedValue= gvPerson.SelectedRow.Cells[6].Text;



如何解决这是为了在选择行时显示ddl的值。

提前感谢您的回复。

干杯。


How to fix this to show the value on ddl when selecting a row.
Thank you in advance for your reply.
Cheers.

推荐答案

使用下面的代码:

Use below code:
ddListPerson.ClearSelection();

// If it is value of the dropdown then use FindByValue()
ddListPerson.Items.FindByValue(gvPerson.SelectedRow.Cells[6].Text).Selected = true;

// OR If it is display text of the dropdown then use FindByText()
ddListPerson.Items.FindByText(gvPerson.SelectedRow.Cells[6].Text).Selected = true;



确保在使用FindByValue()方法之前正确加载了名称(连接)。


Make sure that name(concatenated) is loaded properly before use FindByValue() method.


谢谢你,我从来没有使用该方法将两列连接在一起,所以我有问题在下拉列表中显示。如果其他人有同样的问题,我会给出一个适合我的解决方案:

Thank you, I never used the method to concatenate two columns in one, so i had the problem to show that in dropdown list. In case that someone else has the same problem I'll give a solution that worked for me:
ddListPerson.SelectedItem.Text  = gvPerson.SelectedRow.Cells[6].Text;





再次感谢大家。

干杯。



Once again thank you all.
Cheers.


这篇关于有问题在SelectedIndexChanged上从GridView显示DropDownList的值!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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