2013-01-25 165 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。