单击编辑时在gridview的下拉列表中显示选定的项目 [英] Displaying selected item in dropdownlist in gridview when click on edit

查看:80
本文介绍了单击编辑时在gridview的下拉列表中显示选定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

我已经创建了一个gridview.如果我单击编辑按钮,它必须在某些字段下显示下拉列表.我执行到这里.

现在,我想在下拉列表中显示已经选择的项目,但是我要按字母顺序获取列表中的所有项目.

例如:

苹果

男孩



大象..按此顺序.

但是,如果我单击编辑"按钮,它必须显示具有:


苹果

男孩

大象-在下拉列表中.

U plz可以帮我吗?这里是已经选择的项目猫". ...

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


推荐答案

您可以使用bind绑定数据库中的值

示例如下:

< 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 =无效" 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 =无效" Value ="0"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>

< ItemStyle Width ="100px"></ItemStyle>
</asp:TemplateField></pre>
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>


这非常简单.您将所选项目猫"保留在临时存储架中.在PageLoad事件上,设置GridView类的SelecteIndex属性.有关更多详细信息,请转到 http://msdn.microsoft. com/en-us/library/system.web.ui.webcontrols.gridview.selectedindex.aspx [
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[^]


这篇关于单击编辑时在gridview的下拉列表中显示选定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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