在GridView的EditTemplates使用的DropDownList [英] Using DropDownList in EditTemplates of a GridView

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

问题描述

我的工作在Asp.Net一个GridView。在最初一个页面加载,我的gridview的样子:

I am working on a GridView in Asp.Net. When initially a the Page Loads, my gridview look like:

当用户点击,编辑成一排,我使用编辑模板,以显示域在DropDownList中。但问题是,当DROPDOWNLIST变负载数据,也就失去了域的当前值。
如果我想编辑第4行,这是当前设置为计算机的域正在得到改变为工商管理硕士这是ofcourse第一个元素返回的数据源。

When a user clicks, to edit a row, I am using edit templates to show 'Domain' in a DropDownList. But problem is , when the DropDownlist gets load with data, it lost the current value of the 'Domain'.
i.e If I want to edit 4th Row, its domain which is currently set to 'Computers' is getting changed to 'MBA' which is ofcourse the first element return by the DataSource.


我想显示的当前值(计算机)中的DropDownList选定的值。但我无法得到域,正在编辑的价值。


I want to display the current value ('computers') as the selected value in DropDownList. But I am unable to get the value of Domain, which is being edited.

推荐答案

要解决的异常使用AppendDataBoundItems =真。

to solve exception use AppendDataBoundItems="true".

<asp:DropDownList ID="ddlCategory" runat="server" SelectedValue='<%# Eval("Domain") %>' 
        DataSourceID="datasource"
            DataTextField="text" DataValueField="value" AppendDataBoundItems="true">
            <asp:ListItem Text="Select..." Value=""></asp:ListItem>
        </asp:DropDownList>

这篇关于在GridView的EditTemplates使用的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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