Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
-----------
C#
<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>
Posted
Updated 15-Feb-12 20:45pm
v4
Comments
Anuja Pawar Indore 16-Feb-12 2:46am    
Added pre tag

1 solution

For displaying value instead of id you need to change like this...


first of all you need to add that value filed in your select query of your drop down if it would not there...

for example..


SQL
select name,id from student


now change your drop down design like this...


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


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..

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



this way you can solve your problem...
 
Share this answer
 
Comments
gani7787 17-Feb-12 5:30am    
i am using Ajax combobox and asp label in Gridview

my location text values and ID is available in the dropdown itself.

when i stored in the DB i used to store the values of Dropdown ID,

while i am bounding the row, just i want to display the text values which is correspondingly stored in DB as ID.

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

<asp:TemplateField HeaderText="Cabin">
<edititemtemplate>
<cc1:ComboBox ID="ddlLocation" runat="server" DropDownStyle="DropDownList" SelectedValue='<%# Bind("Location") %>' Width="60px" AutoPostBack="true" CaseSensitive="false" AutoCompleteMode="SuggestAppend" CssClass="WindowsStyle" ItemInsertLocation="OrdinalText">
<asp:ListItem Text="--Select--" Value="">--Select--
<asp:ListItem Value="1" Text="A">
<asp:ListItem Value="2" Text="B">
<asp:ListItem Value="3" Text="C">
<asp:ListItem Value="4" Text="D">


<itemtemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%# Eval("Location") %>'>





For the above example,

I have stored ddlvalue = "2" and stored in DB.

while i'm bounding the row i want to display the text as ="B" in the labelcabin.

How to do this..?
.

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