Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Respected sir,

I have created a gridview. if i click on edit button, it has to display drop down list under some fields. I executed till here.

Now i want to display already selected items in drop downlist, But Im getting all the items in the list in Alphabetical order.

for ex:

Apple

Boy

Cat

Elephant.. In this order.

But if i click on edit button, It must display has :
Cat

Apple

Boy

Elephant -- in Drop down list.

Can U plz help me...Here "Cat" which is already selected item....

Posted
Comments
Sergey Alexandrovich Kryukov 24-Aug-11 0:48am    
Why it's a problem? What did you try so far?
--SA
srikanth.pandu 24-Aug-11 3:52am    
Once see this link below
http://www.obout.com/grid/grid_templates_dropdown_with_new.aspx
Now click on edit button, the item in dropdownlist will not change
I want the code.I tried im getting items in dropdownlist which are not selected can u help for getting selected items in it.

You can use bind to bind a value from database

example is given below:

<pre lang="c#">
<asp:TemplateField HeaderText="Status" ItemStyle-Width="100px">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("STATUS")%>'
Enabled="false">
<asp:ListItem Text="Active" Value="1"></asp:ListItem>
<asp:ListItem Text="Inactive" Value="0"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("STATUS")%>'>
<asp:ListItem Text="Active" Value="1"></asp:ListItem>
<asp:ListItem Text="Inactive" Value="0"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>

<ItemStyle Width="100px"></ItemStyle>
</asp:TemplateField></pre>
 
Share this answer
 
Itz pretty simple. You keep the selected item 'Cat' in temporary storage holder. On PageLoad event, set the SelecteIndex property of GridView class. For further details, go thro http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindex.aspx[^]
 
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