title: Add generated attendance details to Database asp.net c#
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>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
      }
  
         
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/User.master" AutoEventWireup="true" CodeFile="UserAttendance.aspx.cs" Inherits="UserAttendance" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"&gt;
      &lt;style type="text/css"&gt;
          .auto-style1 {
              width: 100%;
          }
          .auto-style2 {
              width: 179px;
          }
          .auto-style3 {
              width: 6px;
          }
      &lt;/style&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;table class="auto-style1"&gt;
              &lt;tr&gt;
                  &lt;td class="auto-style2"&gt;
                      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:studentConnectionString %&gt;" SelectCommand="SELECT [Course] FROM [Course]"&gt;&lt;/asp:SqlDataSource&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Course" DataValueField="Course"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="Semester" DataValueField="Semester"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource3" DataTextField="Subject" DataValueField="Subject"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" Width="49px" /&gt;
                  &lt;/td&gt;
                  &lt;td class="auto-style3"&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="auto-style2"&gt;
                      &amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="False"&gt;&lt;/asp:Calendar&gt;
                  &lt;/td&gt;
                  &lt;td class="auto-style3"&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="auto-style2"&gt;
                      &amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="TextBox1" runat="server" Visible="False"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
                  &lt;td class="auto-style3"&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="auto-style2"&gt;
                      &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:studentConnectionString %&gt;" SelectCommand="SELECT [Semester] FROM [Semester]"&gt;&lt;/asp:SqlDataSource&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"&gt;
                          &lt;AlternatingRowStyle BackColor="White" /&gt;
                          &lt;Columns&gt;
                              &lt;asp:TemplateField&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:DropDownList ID="DropDownList4" runat="server"&gt;
                                          &lt;asp:ListItem&gt;Present&lt;/asp:ListItem&gt;
                                          &lt;asp:ListItem&gt;Absent&lt;/asp:ListItem&gt;
                                          &lt;asp:ListItem&gt;Holiday&lt;/asp:ListItem&gt;
                                      &lt;/asp:DropDownList&gt;
                                  &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                          &lt;/Columns&gt;
                          &lt;EditRowStyle BackColor="#2461BF" /&gt;
                          &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
                          &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
                          &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt;
                          &lt;RowStyle BackColor="#EFF3FB" /&gt;
                          &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt;
                          &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
                          &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
                          &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
                          &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
                      &lt;/asp:GridView&gt;
                  &lt;/td&gt;
                  &lt;td class="auto-style3"&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="auto-style2"&gt;
                      &lt;asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="&lt;%$ ConnectionStrings:studentConnectionString %&gt;" SelectCommand="SELECT [Subject] FROM [Subject]"&gt;&lt;/asp:SqlDataSource&gt;
                  &lt;/td&gt;
                  &lt;td style="text-align: justify"&gt;
                      &lt;asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Save" Visible="False" Width="58px" /&gt;
                  &lt;/td&gt;
                  &lt;td class="auto-style3"&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"&gt;
  &lt;/asp:Content&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have a textbox which contains date(out side the Gridview)
  I have a dropdownlist in the gridview as a templatefield(Absent/Present)
  I have a button called "save" outside of the grid view
  When I press the save button the details should go to database and should be saved in a table Attendance.
  Columns of Attendance Table
  1.ID
  2.Name
  3.Course
  4.Semester
  5.Date
  6.Status(Absent/Present)
  <a href="https://i.stack.imgur.com/aXXHs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aXXHs.png" alt="Image of the Webform"></a></p>