贴子地址:
http://topic.youkuaiyun.com/u/20081022/22/a2565ec7-cfbe-419f-bf6a-09af93c7ed8d.html?seed=1470380539
- <!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>
- <style>
- .black_overlay
- {
- display: none;
- position: absolute;
- top: 0%;
- left: 0%;
- width: 100%;
- height: 100%;
- background-color: black;
- z-index: 1001;
- -moz-opacity: 0.8;
- opacity: .80;
- filter: alpha(opacity=80);
- }
- .white_content
- {
- display: none;
- position: absolute;
- top: 25%;
- left: 25%;
- width: 50%;
- height: 50%;
- padding: 16px;
- border: 1px solid orange;
- background-color: white;
- z-index: 1002;
- overflow: auto;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- </div>
- <asp:GridView ID="GridView1" runat="server" Height="101px" Width="257px" CellPadding="4"
- ForeColor="#333333" GridLines="None">
- <RowStyle BackColor="#EFF3FB" />
- <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
- <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
- <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
- <EditRowStyle BackColor="#2461BF" />
- <AlternatingRowStyle BackColor="White" />
- </asp:GridView>
- <input id="Button3" type="button" value="添加" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'" />
- <div id="light" class="white_content">
- 添加记录<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <br />
- <asp:Button ID="Button2" runat="server" Text="保存" OnClick="Button2_Click" />
- <a href="javascript:void(0)" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">
- 关闭</a></div>
- <div id="fade" class="black_overlay">
- </div>
- </form>
- </body>
- </html>
-
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- BindGrid();
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- if (TextBox1.Text.Trim() != "")
- {
- string sql = string.Format("insert into table_2(name) values('{0}')", TextBox1.Text.Trim());//添加记录
- SqlHelper.ExecuteNonQuery(SqlHelper.conn, CommandType.Text, sql);
- BindGrid();
- }
- }
- //绑定
- private void BindGrid()
- {
- string sql = "select name from table_2";
- DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.conn, CommandType.Text, sql);//返回数据
- GridView1.DataSource = ds;
- GridView1.DataBind();
- }