面对Asp.net Gridview中的编辑项模板中的问题....编辑记录时。 [英] Facing problem in Edit Item Template in Asp.net Gridview....While Editing Record.

查看:65
本文介绍了面对Asp.net Gridview中的编辑项模板中的问题....编辑记录时。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好亲爱的朋友们,



我在Asp.net Gridview中遇到编辑项目模板的问题。



我在编辑项模板中有一个内部网格视图的下拉列表。在这个下拉列表中,它有选择的选项。



存储在数据库中时,用户将从下拉列表中选择并保存。



并且对于此记录,我们在gridview中有编辑,更新选项。



编辑记录时,显示-----选择 - -----

我们已经从下拉列表中选择了该选项,它必须在编辑时显示所选的选项。



这是我的标记代码。



 <   asp:TemplateField     HeaderText   =  设备类型 >  
< HeaderStyle 宽度 = 100px / >
< ItemStyle 宽度 = 100px / >

< EditItemTemplate >
< asp :DropDownList ID = DDLEquipmentTypeEdit runat = server DataValueField = EquipmentType >
< asp:ListItem 已选择 = < span class =code-keyword> True = 0 > ----选择--- < / asp:ListItem >
< asp:ListItem > CPU < / asp:ListItem >
< asp:ListItem > 监控< / asp:ListItem >
< asp:ListItem > 打印机< / asp: ListItem >
< asp:ListItem > 扫描程序< / asp:ListItem >
< asp:ListItem > 笔记本电脑< / asp:ListItem >
< span class =code-keyword>< / asp:DropDownList >
< asp:RequiredFieldValidator ID = rfv1rv runat = server ControlToValidate = DDLEquipmentTypeEdit ErrorMessage = 选择设备类型 文本 = * ValidationGroup = validationEDIT InitialValue = 0 / >
< / EditItemTemplate >

< ItemTemplate >
< asp:标签 ID = lblitemddlEquipmenttype runat = server 文字 =' <% #Eval( Equipment_type%> ' / >
< / ItemTemplate >
< FooterTemplate >
< < span class =code-leadattribute> asp:DropDownList ID = ddlftrEquipment_type runat = server 宽度 = 100px < span class =code-attribute> 高度 = 23px CssClass = text_form_fields_ddl DataValueField = EquipmentType 工具提示 = 请选择设备类型 >
< asp:ListItem > CPU < / asp:ListItem >
< asp:ListItem > 监控< / asp:ListItem >
< span class =code-keyword>< as p:ListItem > 打印机< / asp:ListItem >
< asp:ListItem > 扫描程序< / asp:ListItem >
< asp:ListItem > 笔记本电脑< / asp:ListItem > - %>
< / asp:DropDownList >
< asp:RequiredFieldValidator ID = rfvEquipmentType runat = server ControlToValidate = ddlftrEquipment_type ErrorMessage = 选择设备类型 文字 = * ValidationGroup = 验证 InitialValue = 0 / >
< / FooterTemplate >
< / asp:TemplateField >







请告诉我怎么做?



在此先感谢。

解决方案

代码中的这样的东西可能会这样做:

 ddlftrEquipmentType.SelectedValue = dsEquipment [  EquipmentType]。ToString(); 


我想你会在你的Gridview控件上的RowCommand事件中做到这一点,但我猜一点,因为我只是从一个DetailsView控件做到这一点它是ItemCommand事件的地方。



这可能会指出你做正确的方向:



http://stackoverflow.com/questions/206983/putting-一个-gridview的行式 - 编辑模式编程

Hello My Dear FRIENDS,

am facing problem with Edit Item Template in Asp.net Gridview.

I have a dropdownlist Inside Gridview in Edit Item Template. In this dropdownlist it has options to select.

While storing in database, user will select from dropdownlist and it will save.

and for this record, we have edit,update option inside gridview.

While editing the record, it shows -----Select------
Already we have selected the option from dropdownlist, it must show the selected option while editing.

This is my Markup Code.

<asp:TemplateField HeaderText="Equipment Type">
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />

<EditItemTemplate>
<asp:DropDownList ID="DDLEquipmentTypeEdit" runat="server" DataValueField="EquipmentType">
<asp:ListItem Selected="True" Value="0">---- Select ---</asp:ListItem>
   <asp:ListItem>CPU</asp:ListItem>
   <asp:ListItem>Monitor</asp:ListItem>
   <asp:ListItem>Printer</asp:ListItem>
   <asp:ListItem>Scanner</asp:ListItem>
   <asp:ListItem>Laptop</asp:ListItem>
    </asp:DropDownList>
<asp:RequiredFieldValidator ID="rfv1rv" runat="server" ControlToValidate="DDLEquipmentTypeEdit" ErrorMessage="Select Equipment Type" Text="*" ValidationGroup="validationEDIT" InitialValue="0"/>
</EditItemTemplate>

<ItemTemplate>
<asp:Label ID="lblitemddlEquipmenttype" runat="server" Text='<%#Eval("Equipment_type") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlftrEquipment_type" runat="server" Width="100px" Height="23px" CssClass="text_form_fields_ddl" DataValueField="EquipmentType" ToolTip="Please Select Equipment Type">
   <asp:ListItem>CPU</asp:ListItem>
   <asp:ListItem>Monitor</asp:ListItem>
   <asp:ListItem>Printer</asp:ListItem>
   <asp:ListItem>Scanner</asp:ListItem>
   <asp:ListItem>Laptop</asp:ListItem>--%>
    </asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvEquipmentType" runat="server" ControlToValidate="ddlftrEquipment_type" ErrorMessage="Select Equipment Type" Text="*" ValidationGroup="validation" InitialValue="0"/>
</FooterTemplate>
</asp:TemplateField>




Please can you show me how to do this ?

Thanks in advance.

解决方案

Something like this in the code would probably do it:

ddlftrEquipmentType.SelectedValue = dsEquipment["EquipmentType"].ToString();


I think you would do it inside the RowCommand event on your Gridview control, however I'm guessing a little as I've only done this from a DetailsView control where it's the ItemCommand event.

This may point you in the right direction for what to do though:

http://stackoverflow.com/questions/206983/putting-a-gridview-row-in-edit-mode-programmatically


这篇关于面对Asp.net Gridview中的编辑项模板中的问题....编辑记录时。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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