using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class UserAttendance : System.Web.UI.Page
{
SqlConnection vid = new SqlConnection("Data Source=DESKTOP-430E2O0\\SQLEXPRESS;Initial Catalog=mca;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Calendar1.Visible = true;
TextBox1.Visible = true;
String str = "select * from Student where (Course like '%' + @search + '%')";
String str1 = "select * from Student where (Semester like '%' + @search + '%')";
SqlCommand xp = new SqlCommand(str, vid);
SqlCommand xp1 = new SqlCommand(str1, vid);
xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem.Text;
xp1.Parameters.Add("@search", SqlDbType.NVarChar).Value = DropDownList2.SelectedItem.Text;
vid.Open();
xp.ExecuteNonQuery();
xp1.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
da.SelectCommand = xp1;
DataSet ds = new DataSet();
da.Fill(ds, "Course");
da.Fill(ds, "Semester");
GridView1.DataSource = ds;
GridView1.DataBind();
vid.Close();
Button2.Visible = true;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;
}
protected void Button2_Click(object sender, EventArgs e)
{
//I wish to use this button to save details to the database
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/User.master" AutoEventWireup="true" CodeFile="UserAttendance.aspx.cs" Inherits="UserAttendance" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 179px;
}
.auto-style3 {
width: 6px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" runat="server">
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Course] FROM [Course]"></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Course" DataValueField="Course">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="Semester" DataValueField="Semester">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource3" DataTextField="Subject" DataValueField="Subject">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" Width="49px" />
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="False"></asp:Calendar>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Semester] FROM [Semester]"></asp:SqlDataSource>
</td>
<td>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server">
<asp:ListItem>Present</asp:ListItem>
<asp:ListItem>Absent</asp:ListItem>
<asp:ListItem>Holiday</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Subject] FROM [Subject]"></asp:SqlDataSource>
</td>
<td style="text-align: justify">
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Save" Visible="False" Width="58px" />
</td>
<td class="auto-style3"> </td>
</tr>
</table>
</form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
</asp:Content>
我有一个包含日期的文本框(Gridview外面)
我在gridview中有一个下拉列表作为模板字段(Absent / Present)
我在网格视图外面有一个名为“save”的按钮
当我按下保存按钮时,详细信息应该转到数据库,并应保存在表格中。
出勤表的列
1.ID
2.Name
3.Course
4.Semester
5.Date
6.Status(缺席/礼物)