Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

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

Something like this in the code would probably do it:
C#
ddlftrEquipmentType.SelectedValue = dsEquipment["EquipmentType"].ToString();
 
Share this answer
 
v2
Comments
HYD Webdeveloper 17-Jul-13 4:45am    
where should i wite ur code, i mean which event ?
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
 
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