本文介绍了如何在GridView下拉列表中获取文本值而不是Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中使用下拉菜单.

我正在基于编辑"和更新"模式显示值.

我正在获取下拉值,并将其绑定到gridview中.

我想在下拉列表中显示值而不是ID.

如何在selectedvalue =''<%#Eval(Emp)%>''
中给出条件
看到我的代码
-----------

I am using dropdown inside the gridview.

I am displaying a values based on my "Edit" and "Update" Mode.

I am fetching the dropdown valus and bind it in the gridview.

I want to display the values instead of ID in the dropdown.

How we can give the condition in the selectedvalue = ''<%#Eval(Emp)%>''

see my code
-----------

<asp:TemplateField HeaderText="EmpName">
   <EditItemTemplate> 
      <cc1:ComboBox ID="ddlEmp"  runat="server" DropDownStyle="DropDownList" SelectedValue='<%# Bind("EmpID") %>' Width="60px" AutoPostBack="true" CaseSensitive="false" AutoCompleteMode="SuggestAppend" CssClass="WindowsStyle" ItemInsertLocation="OrdinalText">
   <asp:ListItem Text="--Select--" Value="">--Select--  
   </asp:ListItem>                            
   <asp:ListItem Value="1" Text="Ramesh"></asp:ListItem>
   <asp:ListItem Value="2" Text="Raghu"></asp:ListItem>
   <asp:ListItem Value="3" Text="Raj"></asp:ListItem>
   <asp:ListItem Value="4" Text="Albert"></asp:ListItem>
  </cc1:ComboBox>
                            </EditItemTemplate>
                             <ItemTemplate> 
                                    <asp:Label ID="lblLocation" runat="server" Text='<%# Eval("EmpID") %>'></asp:Label> 
                            </ItemTemplate>

推荐答案

select name,id from student



现在像这样更改您的drop down 设计...




now change your drop down design like this...


dropdwon.datavaluefiled = "id";
dropdwon.datatextfiled = "name";



然后将datasetdatatable绑定到drop down,这样它将在drop down 文本字段中显示名称,并将id作为值显示.


为了根据选择获得价值或文本,您需要像这样的东西.



then bind your dataset OR datatable to your drop down so it will display name in drop down text filed and id as value.


for getting value or text as per selection you need something like this..

dropdown.selectedvalue //for getting id
dropdown.selecteditem.text //for getting name from dropdown




这样可以解决您的问题...




this way you can solve your problem...


这篇关于如何在GridView下拉列表中获取文本值而不是Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 10:55