要求:单击(插入)按钮时,应在gridview中显示一个新行。该行旁边还有保存和取消链接。
的.aspx
<asp:Panel ID = "pnlForAddCategory" runat="server" ScrollBars="Auto" >
<asp:GridView ID="grdAddCategory" runat="server" CellPadding="4" CellSpacing="1" Width="90%" BackColor="#CCCCCC"
style="table-layout:fixed" GridLines="None"
HeaderStyle-CssClass="tableHeaderRow" AlternatingRowStyle-CssClass="tableRow" RowStyle-CssClass="tableAltRow"
RowStyle-HorizontalAlign="Left" OnRowEditing="grdAddCategory_RowEditing" OnRowCancelingEdit="grdAddCategory_RowCancelingEdit" OnRowUpdating="grdAddCategory_RowUpdating" ShowFooter="true" >
<Columns>
<asp:TemplateField HeaderStyle-Width="70px">
<ItemTemplate>
<%--<input value='<%# Eval("CategoryId") %>' type="checkbox" id="chkbxCtgry" name="chkbxCtgry" />--%>
<asp:CheckBox ID="chkbxCtgry" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name">
<ItemTemplate>
<asp:Label ID="lblPrdCategory" runat="server" Text='<%# Bind("ProductName") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddProductName" runat="server" SelectedValue='<%# Bind("ProductName") %>' >
<asp:ListItem Text="maths" />
<asp:ListItem Text="history" />
<asp:ListItem Text="science" />
<asp:ListItem Text="social" />
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category Name" >
<ItemTemplate>
<asp:Label ID="lblctgryName" runat="server" Text='<%# Bind("CategoryName") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtbxctgryName" runat="server" Text= '<%# Bind("CategoryName") %>' ToolTip='<%#Eval("CategoryId")%>' Maxlength="255"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false" >
<ItemTemplate>
<asp:Label ID="lblCategoryId" Visible="false" runat="server" Text='<%# Bind("CategoryId") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtbxCategoryId" runat="server" Text= '<%# Bind("CategoryId") %>' Visible="false" Maxlength="255"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Bind("Status") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddStatus" runat="server" SelectedValue='<%# Bind("Status") %>'>
<asp:ListItem Text="Active" />
<asp:ListItem Text="Inactive" />
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" HeaderStyle-Width="80px" HeaderText="Update" ButtonType="Button" >
<ItemStyle Width="80px" />
</asp:CommandField>
</Columns>
</asp:GridView>
</asp:Panel>