Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

<h2><%: Title %>.</h2>

<section class="container">
  <asp:FormView 
      ID="FvSiteView" 
      runat="server" 
      CssClass="col-md-12"
      AllowPaging="false" 
      DataKeyNames="SiteID" 
      OnItemCommand="FvSiteView_ItemCommand" 
      OnModeChanging="FvSiteView_ModeChanging"
      OnItemInserting="FvSiteView_ItemInserting"
      OnItemUpdating="FvSiteView_ItemUpdating"
      OnDataBound="FvSiteView_DataBound">


    <!-- Enter all item templates here: -->


  </asp:FormView>
</section>

Lorem Ipsum

<ItemTemplate>
  <section class="row">
    <section class="col-xs-8">
      <h3>Form View (Read-Only)</h3>
    </section>
    <section class="col-xs-4 text-right">
      <h3>
        <asp:linkbutton id="btnInsertView" CommandName="New" runat="server" CssClass="glyphicon glyphicon-plus btn"/>
        <asp:linkbutton id="btnEditView" CommandName="Edit" runat="server" CssClass="glyphicon glyphicon-pencil btn"/>
        <asp:linkbutton id="btnListView" CommandName="ListView" runat="server" CssClass="glyphicon glyphicon-th-list btn"/>
      </h3>
    </section>
  </section>
</ItemTemplate>
<EditItemTemplate>
  <section class="row">
    <section class="col-xs-8">
      <h3>Form View (Edit)</h3>
    </section>
    <section class="col-xs-4 text-right">
      <h3>
        <asp:linkbutton id="btnInsertView" CommandName="New" runat="server" CssClass="glyphicon glyphicon-plus btn"/>
        <asp:linkbutton id="btnEditView" CommandName="Edit" runat="server" CssClass="glyphicon glyphicon-pencil btn disabled"/>
        <asp:linkbutton id="btnListView" CommandName="ListView" runat="server" CssClass="glyphicon glyphicon-th-list btn"/>
      </h3>
    </section>
  </section>
</EditItemTemplate>
<InsertItemTemplate>
  <section class="row">
    <section class="col-xs-8">
      <h3>Form View (Insert)</h3>
    </section>
    <section class="col-xs-4 text-right">
      <h3>
        <asp:linkbutton id="btnInsertView" CommandName="New" runat="server" CssClass="glyphicon glyphicon-plus btn disabled"/>
        <asp:linkbutton id="btnEditView" CommandName="Edit" runat="server" CssClass="glyphicon glyphicon-pencil btn disabled"/>
        <asp:linkbutton id="btnListView" CommandName="ListView" runat="server" CssClass="glyphicon glyphicon-th-list btn"/>
      </h3>
    </section>
  </section>
</InsertItemTemplate>
<EmptyDataTemplate>
  <section class="row">
    <section class="col-xs-12">
      <h3>(No record found.)</h3>
    </section>
  </section>
</EmptyDataTemplate>

Lorem Ipsum

Lorem Ipsum

using AssetManagementSystem._DAL_AMSTableAdapters;

Lorem Ipsum

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    PageDataRefresh();
  }
}

private void PageDataRefresh()
{
  string sID = Request.QueryString["id"];
  if (sID == null || sID == "0")
  {
    sID = "0";
    FvSiteView.ChangeMode(FormViewMode.Insert);
  }

  // If sID needs to be integer...
  // int siteID = Convert.ToInt32(sID.ToString());

  /* *********** Configure DAL *********** */
  SiteTableAdapter siteAdapter = new SiteTableAdapter();
  FvSiteView.DataSource = siteAdapter.GetByID(sID);
  FvSiteView.DataBind();
}

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

protected void FvSiteView_DataBound(object sender, EventArgs e)
{
  if (FvSiteView.DataItemCount == 0)
  {
    FvSiteView.ChangeMode(FormViewMode.Insert);
  }
  else
  {
    FvSiteView.ChangeMode(FormViewMode.Edit);
  }
}

Lorem Ipsum

Lorem Ipsum

protected void FvSiteView_ItemCommand(object sender, FormViewCommandEventArgs e)
{
  switch (e.CommandName)
  {
    case "New":
      Response.Redirect("~/Restricted/SiteView.aspx?id=0");
      break;
    case "Cancel":
      FvSiteView.ChangeMode(FormViewMode.ReadOnly);
      PageDataRefresh();
      break;
     case "ListView":
      Response.Redirect("~/Restricted/SiteList.aspx");
      break;
  }
}

Lorem Ipsum

protected void FvSiteView_ModeChanging(object sender, FormViewModeEventArgs e)
{
  // Enable a FormView mode change (Read-Only, Edit/Update, New/Insert, Empty)
  FvSiteView.ChangeMode((FormViewMode)e.NewMode);
  PageDataRefresh();
}

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

<ItemTemplate>

  <section class="row">
    <section class="col-xs-12">
      <table>
        <tr><td>Site ID:</td><td><asp:TextBox ID="txtSiteID" runat="server" Enabled="False" Text='<%#Eval("SiteID") %>'></asp:TextBox></td></tr>
        <tr><td>Site Name:</td><td><asp:TextBox ID="txtSiteName" runat="server" Enabled="False" Text='<%#Eval("SiteName") %>'></asp:TextBox></td></tr>
        <tr><td>Address Line 1:</td><td><asp:TextBox ID="txtAddress1" runat="server" Enabled="False" Text='<%#Eval("[Address 1]") %>'></asp:TextBox></td></tr>
        <tr><td>Address Line 2:</td><td><asp:TextBox ID="txtAddress2" runat="server" Enabled="False" Text='<%#Eval("[Address 2]") %>'></asp:TextBox></td></tr>
        <tr><td>City:</td><td><asp:TextBox ID="txtCity" runat="server" Enabled="False" Text='<%#Eval("City") %>'></asp:TextBox></td></tr>
        <tr><td>Post Code:</td><td><asp:TextBox ID="txtPostCode" runat="server" Enabled="False" Text='<%#Eval("PostCode") %>'></asp:TextBox></td></tr>
        <tr><td>Status:</td><td><asp:TextBox ID="txtStatus" runat="server" Enabled="False" Text='<%#Eval("Status") %>'></asp:TextBox></td></tr>
      </table>
    </section>
  </section>

</ItemTemplate>

Lorem Ipsum

<EditItemTemplate>

  <section class="row">
    <section class="col-xs-12">
      <table>
        <tr><td>Site ID:</td><td><asp:TextBox ID="txtSiteID" runat="server" Enabled="True" Text='<%#Bind("SiteID") %>'></asp:TextBox></td></tr>
        <tr><td>Site Name:</td><td><asp:TextBox ID="txtSiteName" runat="server" Enabled="True" Text='<%#Bind("SiteName") %>'></asp:TextBox></td></tr>
        <tr><td>Address Line 1:</td><td><asp:TextBox ID="txtAddress1" runat="server" Enabled="True" Text='<%#Bind("[Address 1]") %>'></asp:TextBox></td></tr>
        <tr><td>Address Line 2:</td><td><asp:TextBox ID="txtAddress2" runat="server" Enabled="True" Text='<%#Bind("[Address 2]") %>'></asp:TextBox></td></tr>
        <tr><td>City:</td><td><asp:TextBox ID="txtCity" runat="server" Enabled="True" Text='<%#Bind("City") %>'></asp:TextBox></td></tr>
        <tr><td>Post Code:</td><td><asp:TextBox ID="txtPostCode" runat="server" Enabled="True" Text='<%#Bind("PostCode") %>'></asp:TextBox></td></tr>
        <tr><td>Status:</td><td><asp:TextBox ID="txtStatus" runat="server" Enabled="True" Text='<%#Bind("Status") %>'></asp:TextBox></td></tr>

        <tr><td></td><td><asp:LinkButton ID="btnUpdate" runat="server" CommandName="Update" Text="Save" CssClass="btn btn-primary"/></td></tr>
      </table>
    </section>
  </section>

</EditItemTemplate>

Lorem Ipsum

 

<InsertItemTemplate>

  <section class="row">
    <section class="col-xs-12">
      <table>
        <tr><td>Site ID:</td><td><asp:TextBox ID="txtSiteID" runat="server" Enabled="True" Text='<%#Bind("SiteID") %>'></asp:TextBox></td></tr>
        <tr><td>Site Name:</td><td><asp:TextBox ID="txtSiteName" runat="server" Enabled="True" Text='<%#Bind("SiteName") %>'></asp:TextBox></td></tr>
        <tr><td>Address Line 1:</td><td><asp:TextBox ID="txtAddress1" runat="server" Enabled="True" Text='<%#Bind("[Address 1]") %>'></asp:TextBox></td></tr>
        <tr><td>Address Line 2:</td><td><asp:TextBox ID="txtAddress2" runat="server" Enabled="True" Text='<%#Bind("[Address 2]") %>'></asp:TextBox></td></tr>
        <tr><td>City:</td><td><asp:TextBox ID="txtCity" runat="server" Enabled="True" Text='<%#Bind("City") %>'></asp:TextBox></td></tr>
        <tr><td>Post Code:</td><td><asp:TextBox ID="txtPostCode" runat="server" Enabled="True" Text='<%#Bind("PostCode") %>'></asp:TextBox></td></tr>
        <tr><td>Status:</td><td><asp:TextBox ID="txtStatus" runat="server" Enabled="True" Text='<%#Bind("Status") %>'></asp:TextBox></td></tr>

        <tr><td></td><td><asp:LinkButton ID="btnInsert" runat="server" CommandName="Insert" Text="Submit" CssClass="btn btn-primary"/></td></tr>
      </table>
    </section>
  </section>

</InsertItemTemplate>

Lorem Ipsum

<EmptyDataTemplate>

<EmptyDataTemplate>
  <section class="row">
    <section class="col-xs-12">
      <h3>(No record found.)</h3>
    </section>
  </section>
</EmptyDataTemplate>

Lorem Ipsum

protected void FvSiteView_ItemInserting(object sender, FormViewInsertEventArgs e)
{
  FvSiteView_CallInsertOrUpdate("Insert");
}

protected void FvSiteView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
  FvSiteView_CallInsertOrUpdate("Update");
}

protected void FvSiteView_CallInsertOrUpdate(string CallCommand)
{
  // Code versions of all controls
  TextBox siteID_txt = (TextBox)FvSiteView.FindControl("txtSiteID");
  TextBox siteName_txt = (TextBox)FvSiteView.FindControl("txtSiteName");
  TextBox address1_txt = (TextBox)FvSiteView.FindControl("txtAddress1");
  TextBox address2_txt = (TextBox)FvSiteView.FindControl("txtAddress2");
  TextBox city_txt = (TextBox)FvSiteView.FindControl("txtCity");
  TextBox postCode_txt = (TextBox)FvSiteView.FindControl("txtPostCode");
  TextBox status_txt = (TextBox)FvSiteView.FindControl("txtStatus");

  // Assign all text properties of controls to variables
  // Or skip this and assign straight into INSERT/UPDATE parameters
  string siteID = siteID_txt.Text;
  string siteName = siteName_txt.Text;
  string address1 = address1_txt.Text;
  string address2 = address2_txt.Text;
  string city = city_txt.Text;
  string postCode = postCode_txt.Text;
  string status = status_txt.Text;

  SiteTableAdapter siteAdapter = new SiteTableAdapter();

  try
  {
    if (CallCommand == "Update")
    {
      string originalID = Request.QueryString["id"].ToString();

      // Conduct Update
      siteAdapter.UpdateRecord(siteID, siteName, address1, address2, city, postCode, status, originalID);

      Response.Write("<script LANGUAGE='JavaScript' >alert('Record Edited')</script>");

      // Return to Read Only mode
      FvSiteView.ChangeMode(FormViewMode.ReadOnly);
      PageDataRefresh();
    }
    else if (CallCommand == "Insert")
    {
      siteAdapter.InsertRecord(siteID, siteName, address1, address2, city, postCode, status);
      //string newID = siteAdapter.InsertAndReturnID(siteID, siteName, address1, address2, city, postCode, status).ToString();
      Response.Write("<script LANGUAGE='JavaScript' >alert('Record Added')</script>");
      // Redirect User
      Response.Redirect("~/Restricted/SiteView.aspx?id=" + siteID);
    }
  }
  catch (System.Exception ex)
  {
    Response.Write("<script LANGUAGE='JavaScript' >alert('An ERROR occurred connecting to the database.')</script>");
  }
}

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum