网格视图中的问题内联编辑.. [英] Problem in Grid view Inline edit ..

查看:46
本文介绍了网格视图中的问题内联编辑..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gridview标记如下所示...在编辑模式下,下拉列表不会自动选中单元格中的现有数据,



the gridview markup is as below...In edit mode , the dropdown is not getting automatically selected with the existing data in the cell,

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







编辑模式下的代码



gvwMERSFiles.EditIndex = e.NewEditIndex;

gvwMERSFiles。 DataSource = dtStructure;

gvwMERSFiles.DataBind();





也点击取消(取消编辑) )正确检索单元格内容,这意味着数据不会丢失...

任何帮助请...




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

推荐答案

你需要设置< a href =http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue.aspx> SelectedValue [ ^ ] DropDownList的属性 [ ^ ]按 Eval 表达式。

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


这篇关于网格视图中的问题内联编辑..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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