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'中。 –