how to display a row in gridview for insertion on a button click event
Requirement: On clicking (insert) button, a new row should be displayed in the gridview. Also there is save and cancel links beside the row.
.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>
You can use the FooterTemplate
of the GridView
for that.
Example: How to insert record using GridView
精彩评论