2014-07-01 4 views
0

gridview 내부에 드롭 다운 목록이 있습니다. DDL의 값을 편집 모드에서보기 모드와 동일하게하지 않을 것입니다. 그리드 뷰가 편집 모드가되면 DDL 세트의 값이 기본값이됩니다.드롭 다운 목록의 값 설정 OnRowEditing

필자는 채우기 전에 gridview를 편집 모드로 바인딩하려고했지만 null (nFolderId)을 얻습니다. 바인딩 후 nFolderId 스니 j을 시도하면 기본값 (첫 x 째 값)을 얻게됩니다.

그렇다면보기 모드에서 편집 모드로 유지하기 위해 DDL 값을 얻으려면 어떻게해야합니까? 내 영문

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) 
{ 
    GridView1.EditIndex = e.NewEditIndex; 
    GridViewRow row = GridView1.Rows[e.NewEditIndex]; 
    var nFolderId = Convert.ToInt32(((DropDownList)row.FindControl("DropDownListFolders1")).SelectedValue); 
    FillGridView(); 
    GridView1.DataBind(); 
} 
:

<asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing" DataKeyNames="strPositionId,tmVaRPosition,nFoldersId" 
      AllowSorting="True" AutoGenerateColumns="False" SkinID="gridviewGridlinesSkin" OnRowCancelingEdit="GridView1_CancelingEdit" 
      OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting" 
      EmptyDataText="No positions found" OnRowDataBound="GridView1_RowDatabound"> 
      <Columns> 
       <asp:TemplateField> 
        <ItemTemplate> 
         <asp:ImageButton ID="ibEdit" runat="server" AlternateText="Edit" CommandName="Edit" 
          ImageUrl="~/Images/icon_edit.gif" /> 
         <asp:ImageButton ID="ibDelete" runat="server" AlternateText="Delete" CommandName="Delete" 
          ImageUrl="~/Images/icon_delete.gif" OnClientClick='<%# Eval("strPositionName", "return confirm(\"Are you sure you want to delete this entry {0}?\");") %>' /> 
        </ItemTemplate> 
        <EditItemTemplate> 
         <asp:ImageButton ID="ibUpdate" runat="server" AlternateText="Update" CommandName="Update" ImageUrl="~/Images/icon_ok.gif" /> 
         <asp:ImageButton ID="ibCancel" runat="server" AlternateText="Cancel" CommandName="Cancel" ImageUrl="~/Images/icon_cancel.gif" /> 
        </EditItemTemplate> 
        <ItemTemplate> 
         <asp:Label ID="Label3" runat="server" Text='<%# Eval("strFolderName") %>'></asp:Label> 
        </ItemTemplate> 
        <ItemStyle Wrap="False" /> 
       </asp:TemplateField> 
       <asp:TemplateField> 
        <EditItemTemplate> 
         <BrummerComp:SortableDropDownList ID="DropDownListFolders1" Width="141px" runat="server" 
           SkinID="BCdropdownlistSkin"/> 
        </EditItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
     </asp:GridView> 
+0

-보기 모드 편집 모드? – deostroll

+0

@deostroll 뷰 모드에서 이것은 값을 보여주는 레이블 일뿐입니다 – MrProgram

답변

0

는 SelectedValue의 값

<div> 
     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  DataSourceID="SqlDataSource1" 
    onrowdeleting="GridView1_RowDeleting"> 
    <Columns> 
     <asp:BoundField DataField="dd" HeaderText="dd" SortExpression="dd" /> 
     <asp:TemplateField HeaderText="ddd" SortExpression="ddd"> 
      <ItemTemplate> 
       <asp:Label ID="Label1" runat="server" Text='<%# Bind("ddd") %>'></asp:Label> 
      </ItemTemplate> 
      <EditItemTemplate> 
       <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ddd") %>'></asp:TextBox> 
      </EditItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="cate" SortExpression="cate"> 
      <EditItemTemplate> 
       <asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="SqlDataSource12" DataTextField="cate" DataValueField="id" 
        SelectedValue="<%# Bind('cate') %>"> 
       </asp:DropDownList> 
       <asp:SqlDataSource ID="SqlDataSource12" runat="server" 
        ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
        SelectCommand="SELECT * FROM [cate]"></asp:SqlDataSource> 
      </EditItemTemplate> 
      <ItemTemplate> 
       <asp:Label ID="Label2" runat="server" Text='<%# Bind("cate") %>'></asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:CommandField ShowEditButton="True" /> 
    </Columns> 
</asp:GridView> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
    SelectCommand="SELECT * FROM [View_1]"></asp:SqlDataSource> 
     <br /> 
     <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" 
       style="height: 26px" /> 
을 설정 Q. 그래서, 드롭 다운 외모와 두 모드에서 동일한 경험을 가지고

관련 문제