Editing Data using Templated Columns : TemplateField « Data Binding « ASP.Net






Editing Data using Templated Columns

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Editing Data using Templated Columns</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="productsSource" runat="server"
            ProviderName="System.Data.SqlClient" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"
            SelectCommand="Select ProductID, Name, ProductNumber, DaysToManufacture, SellStartDate, ReorderPoint from Production.Product"            
            UpdateCommand="Update Production.Product Set ReorderPoint = @ReorderPoint Where ProductID = @ProductID">            
        </asp:SqlDataSource>
       <asp:GridView ID="gridProducts" runat="server" DataSourceID="productsSource"
            AutoGenerateColumns="False" DataKeyNames="ProductID">              
            <Columns>
                <asp:CommandField ShowEditButton="true" />
                <asp:TemplateField HeaderText="Products">
                    <ItemTemplate>                        
                            <%# Eval("ProductID") %> -
                            <%# Eval("Name") %>                            
                             Product Number: <%# Eval("ProductNumber") %><br />                                 
                            Reorder Point:<%# Eval("ReorderPoint") %><br />
                        </small>
                    </ItemTemplate>
                    <EditItemTemplate>
                            <%# Eval("ProductID") %> -
                            <%# Eval("Name") %>                            
                                  Product Number: <%# Eval("ProductNumber") %><br />                                 
                            Reorder Point:<asp:TextBox Text='<%# Bind("ReorderPoint") %>' runat="server" id="textBox"/>
                        </small>
                    </EditItemTemplate>
                </asp:TemplateField> 
            </Columns>
       </asp:GridView>
    </div>
    </form>
</body>
</html>

 








Related examples in the same category

1.Displaying Column Summaries
2.Displaying Nested Master/Details Forms
3.GridView with Template and backend code
4.Master-Detail GridView in Single Page
5.Using Templated Columns with GridView