zoukankan      html  css  js  c++  java
  • GridView FootRow Insert Sample[Note]

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="VendorEdit.aspx.cs" Inherits="Purchase_VendorEdit" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title>无标题页</title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
            
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#CCCCCC"
                BorderColor
    ="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
                DataKeyNames
    ="VendorID" DataSourceID="VendorDataSource" ForeColor="Black" OnRowCreated="GridView1_RowCreated"
                ShowFooter
    ="True" OnRowCommand="GridView1_RowCommand" AllowPaging="True">
                
    <FooterStyle BackColor="Yellow" BorderColor="#000040" BorderStyle="Dashed" BorderWidth="1px" />
                
    <Columns>
                    
    <asp:TemplateField HeaderText="VendorID" SortExpression="VendorID">
                        
    <EditItemTemplate>
                            
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("VendorID") %>'></asp:Label>
                        
    </EditItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:Button ID="btnClick" runat="server" CommandName="Insert" Text="Insert" />
                        
    </FooterTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label1" runat="server" Text='<%# Bind("VendorID") %>'></asp:Label>
                        
    </ItemTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="VendorName" SortExpression="VendorName">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("VendorName") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label3" runat="server" Text='<%# Bind("VendorName") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newVendorName" runat="server" Text='<%# Bind("VendorName") %>'></asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="VendorDesc" SortExpression="VendorDesc">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("VendorDesc") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label4" runat="server" Text='<%# Bind("VendorDesc") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newVendorDesc" runat="server" Height="30px" Text='<%# Bind("VendorDesc") %>'
                                TextMode="MultiLine">
    </asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:BoundField DataField="VendorLongName" HeaderText="VendorLongName" SortExpression="VendorLongName" />
                    
    <asp:TemplateField HeaderText="VendorTypeID" SortExpression="VendorTypeID">
                        
    <EditItemTemplate>
                            
    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="VendorTypeDataSource"
                                DataTextField
    ="VendorTypeName" DataValueField="VendorTypeID">
                            
    </asp:DropDownList>
                            
    <asp:SqlDataSource ID="VendorTypeDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:BLUEBEANSConnectionString %>"
                                SelectCommand
    ="SELECT [VendorTypeID], [VendorTypeName] FROM [VendorType]"></asp:SqlDataSource>
                        
    </EditItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:DropDownList ID="newVendorType" runat="server" DataSourceID="VendorDataSource"
                                DataTextField
    ="VendorName" DataValueField="VendorID">
                            
    </asp:DropDownList>
                        
    </FooterTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label2" runat="server" Text='<%# Eval("VendorTypeID") %>'></asp:Label>
                        
    </ItemTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="Address1" SortExpression="Address1">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Address1") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label5" runat="server" Text='<%# Bind("Address1") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newVendorAddress1" runat="server" Height="30px" Text='<%# Bind("Address1") %>'
                                TextMode="MultiLine">
    </asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="Address2" SortExpression="Address2">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Address2") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label6" runat="server" Text='<%# Bind("Address2") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newVendorAddress2" runat="server" Height="30px" Text='<%# Bind("Address2") %>'
                                TextMode="MultiLine">
    </asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="Phone1" SortExpression="Phone1">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Phone1") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label7" runat="server" Text='<%# Bind("Phone1") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newPhone1" runat="server" Text='<%# Bind("Phone1") %>'></asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="Phone2" SortExpression="Phone2">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Phone2") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label8" runat="server" Text='<%# Bind("Phone2") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newPhone2" runat="server" Text='<%# Bind("Phone2") %>'></asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="VendorCode" SortExpression="VendorCode">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("VendorCode") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label9" runat="server" Text='<%# Bind("VendorCode") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newVendorCode" runat="server" Text='<%# Bind("VendorCode") %>'></asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="ZipCode" SortExpression="ZipCode">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("ZipCode") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label10" runat="server" Text='<%# Bind("ZipCode") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newZipCode" runat="server" Text='<%# Bind("ZipCode") %>'></asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:TemplateField HeaderText="Contactor" SortExpression="Contactor">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Contactor") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label11" runat="server" Text='<%# Bind("Contactor") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newContactor" runat="server" Text='<%# Bind("Contactor") %>'></asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:BoundField DataField="VendorRank" HeaderText="VendorRank" SortExpression="VendorRank" />
                    
    <asp:TemplateField HeaderText="BankCardNo" SortExpression="BankCardNo">
                        
    <EditItemTemplate>
                            
    <asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("BankCardNo") %>'></asp:TextBox>
                        
    </EditItemTemplate>
                        
    <ItemTemplate>
                            
    <asp:Label ID="Label12" runat="server" Text='<%# Bind("BankCardNo") %>'></asp:Label>
                        
    </ItemTemplate>
                        
    <FooterTemplate>
                            
    <asp:TextBox ID="newBankCardNo" runat="server" Text='<%# Bind("BankCardNo") %>'></asp:TextBox>
                        
    </FooterTemplate>
                    
    </asp:TemplateField>
                    
    <asp:CommandField />
                    
    <asp:CommandField ShowEditButton="True" />
                
    </Columns>
                
    <RowStyle BackColor="White" />
                
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                
    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
            
    </asp:GridView>
            
    &nbsp; &nbsp;
        
        
    </div>
            
    <asp:SqlDataSource ID="VendorDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:BLUEBEANSConnectionString %>"
                SelectCommand
    ="SELECT * FROM [Vendor]"></asp:SqlDataSource>
        
    </form>
    </body>
    </html>


     1using System;
     2using System.Data;
     3using System.Configuration;
     4using System.Collections;
     5using System.Web;
     6using System.Web.Security;
     7using System.Web.UI;
     8using System.Web.UI.WebControls;
     9using System.Web.UI.WebControls.WebParts;
    10using System.Web.UI.HtmlControls;
    11using BlueBeanDemo.Entities;
    12using BlueBeanDemo.Data;
    13
    14
    15public partial class Purchase_VendorEdit : System.Web.UI.Page
    16{
    17    protected void Page_Load(object sender, EventArgs e)
    18    {
    19
    20    }

    21    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    22    {
    23
    24    }

    25    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    26    {
    27        if (e.CommandName.Equals( "Insert"))
    28        {
    29            TextBox newVendorName = (TextBox)this.GridView1.FooterRow.FindControl("newVendorName");
    30            TextBox newVendorDesc = (TextBox)this.GridView1.FooterRow.FindControl("newVendorDesc");
    31            DropDownList newVendorType = (DropDownList)this.GridView1.FooterRow.FindControl("newVendorType");
    32            TextBox newVendorAddress1 = (TextBox)this.GridView1.FooterRow.FindControl("newVendorAddress1");
    33            TextBox newVendorAddress2 = (TextBox)this.GridView1.FooterRow.FindControl("newVendorAddress2");
    34            TextBox newPhone1 = (TextBox)this.GridView1.FooterRow.FindControl("newPhone1");
    35            TextBox newPhone2 = (TextBox)this.GridView1.FooterRow.FindControl("newPhone2");
    36            TextBox newVendorCode = (TextBox)this.GridView1.FooterRow.FindControl("newVendorCode");
    37            TextBox newZipCode = (TextBox)this.GridView1.FooterRow.FindControl("newZipCode");
    38            TextBox newBankCardNo = (TextBox)this.GridView1.FooterRow.FindControl("newBankCardNo");
    39
    40            Vendor vendor = new Vendor();
    41            int totalNumer=20;
    42            totalNumer = totalNumer + 2;
    43            vendor.VendorID = totalNumer;
    44            vendor.VendorName = newVendorName.Text;
    45            vendor.VendorDesc = newVendorDesc.Text;
    46            vendor.VendorTypeID = int.Parse(newVendorType.SelectedValue.ToString());
    47            vendor.Address1 = newVendorAddress1.Text;
    48            vendor.Address2 = newVendorAddress2.Text;
    49            vendor.Phone1 = newPhone1.Text;
    50            vendor.Phone2 = newPhone2.Text;
    51            vendor.VendorCode = newVendorCode.Text;
    52            vendor.ZipCode = newZipCode.Text;
    53            vendor.BankCardNo = newBankCardNo.Text;
    54            try
    55                {
    56                    DataRepository.VendorProvider.Save(vendor);
    57                }

    58                catch(Exception ex)
    59                {
    60                Response.Write(ex.Message);
    61                }

    62
    63                this.GridView1.DataBind();
    64
    65         
    66
    67
    68
    69
    70
    71        }

    72    }

    73}

    74


    效果:

  • 相关阅读:
    JVM 重排序
    Dispatcher & Redirect
    Struts2-ActionContext
    eclipse+tomcat+maven debug的时候总是出现source not found /Edit lookup path...的问题解决方案
    web Listener
    优质博客
    IDEA中jdk设置
    chrome json插件
    IDEA快速复习
    MarkDown编辑器下载
  • 原文地址:https://www.cnblogs.com/SlashOut/p/836683.html
Copyright © 2011-2022 走看看