我仍在学习使用gridviews,事实上,我有一个由三个表组成的访问数据库(作为练习的一部分),并使用连接语句显示所有三个表中的值字段。
conn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;
Data Source =" + Server.MapPath("App_Data\\Shopping List.mdb"));
conn.Open();
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('a connection was established with the database')", true);
DataSet ds = new DataSet();
OleDbDataAdapter dba = new OleDbDataAdapter(@"SELECT Ingredient.IngredientId, Ingredient.IngredientName, Area.AreaName, Recipe.RecipeName, Ingredient.Quantity
FROM (Ingredient
INNER JOIN Area ON Ingredient.AreaId = Area.AreaId)
INNER JOIN Recipe ON Ingredient.RecipeId = Recipe.RecipeId", conn);
dba.Fill(ds);
gridIngredients.DataSource = ds;
gridIngredients.DataBind();
我现在通过将 autoGenerateEditButton 设置为 true 添加了一个编辑按钮。我将如何在行中添加文本框或下拉列表以更新数据?
<asp:GridView ID="gridIngredients" runat="server" AutoGenerateColumns="False"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" ForeColor="Black" GridLines="None"
AutoGenerateEditButton="True"
onselectedindexchanged="gridIngredients_SelectedIndexChanged"
Width="543px" onrowediting="gridIngredients_RowEditing">
<Columns>
<asp:BoundField DataField="IngredientId" HeaderText="ID" />
<asp:BoundField DataField="IngredientName" HeaderText="Ingredient" />
<asp:BoundField DataField="AreaName" HeaderText="Area" />
<asp:BoundField DataField="RecipeName" HeaderText="Recipe" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" />
</Columns>
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
问候