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。
你是否尝试过将'Gridview'放入'UpdatePanel'? –
会尝试。接线看起来好吗? – OneFineDay
您是否有针对您的DDL的现有操作?将'UpdatePanel'包含到'PostBackTrigger'中。 –