0
我在GridView中有一個下拉列表。我不希望DDL中的值在編輯模式下與視圖模式下相同,當gridview進入編輯模式時,DDL set的值爲第一個值爲默認值。設置下拉列表的值OnRowEditing
我試圖在填充和綁定GridView的編輯模式之前獲取值,但後來我得到空(nFolderId)。當我在綁定後嘗試nFolderId片段時,我得到默認值(意思是第一個值)。
那麼我怎樣才能讓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();
}
我的aspx:
<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>
問:那麼,在下拉菜單的外觀和在這兩種模式下同樣的經歷 - 視圖模式和編輯模式? – deostroll
@deostroll在視圖模式下,它只是一個標籤*,顯示值 – MrProgram