2013-01-25 63 views
0

我想綁定DropDownList(DDL)與我的實體數據源。 GridView(GV)綁定到與DDL不同的EntityDataSource。 GV的EntityDataSource具有用於關係的導航屬性'Bag'。在編輯模式中,我可以選擇其他項目,但不會更新該記錄的數據庫。我確實使用了包括在內的用於EntityDataSource中的導航。我確定接線不正確。到目前爲止,我嘗試過搜索沒有運氣。謝謝您的幫助。更新GridView組合框不更新

<asp:TemplateField HeaderText="Bag"> 
    <ItemTemplate > 
    <asp:Label ID="lbEditBag" Text='<%#Eval("Bag.Item1") %>' runat="server" /> 
    </ItemTemplate> 
    <EditItemTemplate > 
    <asp:DropDownList runat="server" ID="ddlBags" DataSourceID="edsBags" DataTextField="Amount" DataValueField="BagId" /> 
    </EditItemTemplate> 
</asp:TemplateField> 
+0

你是否嘗試過將'Gridview'放入'UpdatePanel'? –

+0

會嘗試。接線看起來好嗎? – OneFineDay

+0

您是否有針對您的DDL的現有操作?將'UpdatePanel'包含到'PostBackTrigger'中。 –

回答

0

DonA,如果你還沒有找到你的答案,我會解釋我做了什麼來做一些類似於你的事後我相信。

在GridView我有不同的ASP:TempleteField的,其中一個是這樣的: -

<ItemTemplate> 
    <asp:Label ID="lblActive" runat="server" Text='<%# Bind("Active") %>'></asp:Label> 
</ItemTemplate> 
<EditItemTemplate> 
<%--<asp:TextBox ID="txtboxActive" runat="server" Text='<%# Bind("Active") %>'  Width="20px" TextMode="SingleLine" CssClass="textboxEdit"></asp:TextBox>--%> 
<asp:DropDownList ID="activeDDL" CausesValidation="False" AutoPostBack="False"  runat="server">      <asp:ListItem Text="No" Value="0"></asp:ListItem> 
<asp:ListItem Text="Yes" Value="1" Selected="True"></asp:ListItem> 
    </asp:DropDownList> 
</EditItemTemplate> 

正如你可以看到在EditItemTemplete有兩個下拉列表項(我也留下了類似的代碼,我曾用於綁定到數據庫的DDL值,但我不再使用,所以被註釋掉)

then al ongside的ID,RUNAT = 「服務器」,的DataKeyNames等在

<asp:Gridview ID=""... 

我有

OnRowUpdated="info_GridView_RowUpdated" 

這然後在SQL函數後面我的C#代碼運行與設置更新數據庫表從DDL,像這樣(我還存在一些其他Gridview.Databind()重置我的其他GridView的)

protected void info_GridView_RowUpdated(object sender, GridViewUpdatedEventArgs e) 
{ 
    // The update operation was successful. Retrieve the row being edited. 
    int index = info_GridView.EditIndex; 
    GridViewRow row = info_GridView.Rows[index]; 
    int itemID = Convert.ToInt32(row.Cells[4].Text); // Cells[4] is only one available as others are being edited! 

    // update Active value in the database // 
    comm = new SqlCommand("UPDATE Products SET [email protected] WHERE [email protected]", objConn); 
    comm.Parameters.AddWithValue("@active", ddlValue); // this stores DDL value in database 
    comm.Parameters.AddWithValue("@itemID", itemID);// Convert.ToInt32(propertyRefTextBox.Text)); 

    objConn.Open(); 
    comm.ExecuteNonQuery(); 
    objConn.Close(); 

       // force update and reset selectedIndex of other gridviews // 
    Category_GridView.DataBind(); 
    editImages_GridView.DataBind(); 

    Category_GridView.SelectedIndex = -1; 
    editImages_GridView.SelectedIndex = -1; 

}

希望以上幫助。

Trev。