Click here to Skip to main content
15,881,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the gridview markup is as below...In edit mode , the dropdown is not getting automatically selected with the existing data in the cell,

XML
<asp:GridView  ID="gvwMERSFiles" DataKeyNames="Datafile"  runat="server" Width="269px"
                    AutoGenerateColumns = "false" Font-Names = "Arial"
                   Font-Size = "11pt" AlternatingRowStyle-BackColor = "#e4ebf5"
                   HeaderStyle-BackColor = "#67beda" AllowPaging ="false"  ShowFooter = "true"
                    onrowediting="EditMERSFile"
                   onrowupdating="UpdateMERSFile"  onrowcancelingedit="CancelEdit"
                    style="margin-bottom: 0px" OnRowDataBound="gvwMERSFiles_RowDataBound"
                   >
                  <Columns>
                     <asp:TemplateField>
                       <HeaderTemplate>Data File</HeaderTemplate>
                       <ItemTemplate>
                           <asp:Label ID ="lblDataFile" runat="server" Text='<%#Eval("Datafile") %>'></asp:Label>
                       </ItemTemplate>
                      <EditItemTemplate>
                            <asp:DropDownList ID="ddlGrdEditDataFile" runat="server" DataTextField="Datafile"
                                           dataValueField="Datafile">
                               <asp:ListItem Value="0" Text="<--Select-->" />
                           </asp:DropDownList>
                      </EditItemTemplate>
                      <FooterTemplate>
                          <asp:DropDownList ID="ddlGrdFtrDataFile" runat="server">
                               <asp:ListItem Value="0" Text="<--Select-->" />
                           </asp:DropDownList>
                      </FooterTemplate>
                   </asp:TemplateField>
                   </Columns>
                   <Columns>
                      <asp:TemplateField ItemStyle-Width = "30px" >
                          <HeaderTemplate>File Path</HeaderTemplate>
                           <ItemTemplate>
                               <asp:Label ID="lblFileName" MaxLength="30" runat="server" Text='<%# Eval("FilePath") %>'></asp:Label>
                           </ItemTemplate>
                            <EditItemTemplate>
                                <asp:FileUpload ID="fUpldEditFilepath" runat="server" />
                           </EditItemTemplate>
                           <FooterTemplate>
                               <asp:FileUpload ID="fUpldFtrFilepath" runat="server"  />

                           </FooterTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="Action">
                                   <ItemTemplate>
                                       <asp:LinkButton ID="LinkButton1" Text="Edit" CommandName="Edit" runat="server" />
                                       <asp:LinkButton ID="LinkButton2" Text="Delete" CommandName="Delete" runat="server" />
                                   </ItemTemplate>
                                   <EditItemTemplate>
                                       <asp:LinkButton ID="LinkButton3" Text="Update" CommandName="Update" runat="server" />
                                       <asp:LinkButton ID="LinkButton4" Text="Cancel" CommandName="Cancel" runat="server" />
                                   </EditItemTemplate>
                                   <FooterTemplate>
                                       <asp:Button Text="Add" id="btnAdd" runat="server" CommandName="Add" OnClick="AddNewMERSFile" />
                                   </FooterTemplate>
                               </asp:TemplateField>
                       </Columns>
               </asp:GridView>



Code in edit mode

gvwMERSFiles.EditIndex = e.NewEditIndex;
gvwMERSFiles.DataSource = dtStructure;
gvwMERSFiles.DataBind();


also on clicking the Cancel(cancel edit) the cell content is retrieved correctly, that means the data is not lost...
Any help pls...
Posted
Updated 16-Aug-13 1:11am
v3
Comments
Thanks7872 16-Aug-13 7:06am    
Don't write whole question in title.

1 solution

You need to set the SelectedValue[^] property of DropDownList[^] by Eval Expression.
XML
<EditItemTemplate>
    <asp:DropDownList ID="ddlGrdEditDataFile" runat="server" DataTextField="Datafile" dataValueField="Datafile" SelectedValue='<%# Eval("Datafile") %>'>
       <asp:ListItem Value="0" Text="<--Select-->" />
   </asp:DropDownList>
</EditItemTemplate>
 
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