<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="Ctenar.aspx.cs" Inherits="WebApplication4.WebForm3" %>
<%@ Register Namespace="AspNetTutorial" TagPrefix="my" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>
Detaily ctenare</h2>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KnihyConnectionString %>"
DeleteCommand="DELETE FROM [Ctenari] WHERE [IdCtenar] = @IdCtenar" InsertCommand="INSERT INTO [Ctenari] ([Prijmeni], [Jmeno], [DatumNarozeni], [Adresa]) VALUES (@Prijmeni, @Jmeno, @DatumNarozeni, @Adresa)"
SelectCommand="SELECT * FROM [Ctenari] WHERE ([IdCtenar] = @IdCtenar)" UpdateCommand="UPDATE [Ctenari] SET [Prijmeni] = @Prijmeni, [Jmeno] = @Jmeno, [DatumNarozeni] = @DatumNarozeni, [Adresa] = @Adresa WHERE [IdCtenar] = @IdCtenar">
<DeleteParameters>
<asp:Parameter Name="IdCtenar" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Prijmeni" Type="String" />
<asp:Parameter Name="Jmeno" Type="String" />
<asp:Parameter Name="DatumNarozeni" Type="DateTime" />
<asp:Parameter Name="Adresa" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="IdCtenar" QueryStringField="id" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Prijmeni" Type="String" />
<asp:Parameter Name="Jmeno" Type="String" />
<asp:Parameter Name="DatumNarozeni" Type="DateTime" />
<asp:Parameter Name="Adresa" Type="String" />
<asp:Parameter Name="IdCtenar" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<my:MyFormView ID="FormView1" runat="server" DataKeyNames="IdCtenar" DefaultMode="Insert"
DataSourceID="SqlDataSource1"
RedirectUrl="Ctenari.aspx">
<edititemtemplate>
<table>
<tr>
<td>
Prijmeni:
</td>
<td>
<asp:TextBox ID="PrijmeniTextBox" runat="server" Text='<%# Bind("Prijmeni") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
ControlToValidate="PrijmeniTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Jmemo:
</td>
<td>
<asp:TextBox ID="JmenoTextBox" runat="server" Text='<%# Bind("Jmeno") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="JmenoTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Narozeni:
</td>
<!--<td><asp:Calendar ID="Calendar1" runat="server" SelectedDate='<%# Bind("DatumNarozeni") %>'></asp:Calendar></td>-->
<td>
<asp:TextBox ID="DatumNarozeniTextBox" runat="server" Text='<%# Bind("DatumNarozeni") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*"
ControlToValidate="DatumNarozeniTextBox"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="DatumNarozeniTextBox" ErrorMessage="Neplatne datum"
onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td>
Adresa:
</td>
<td>
<asp:TextBox ID="AdresaTextBox" runat="server" TextMode="MultiLine" Width="400px"
Height="100px" Text='<%# Bind("Adresa") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*"
ControlToValidate="AdresaTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Zmenit" />
<asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Zrusit"
OnClientClick="javascript: return confirm('Opravdu chce te zrusit<');" />
</edititemtemplate>
<insertitemtemplate>
<table>
<tr>
<td>
Prijmeni:
</td>
<td>
<asp:TextBox ID="PrijmeniTextBox" runat="server" Text='<%# Bind("Prijmeni") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
ControlToValidate="PrijmeniTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Jmemo:
</td>
<td>
<asp:TextBox ID="JmenoTextBox" runat="server" Text='<%# Bind("Jmeno") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="JmenoTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Narozeni:
</td>
<!--<td><asp:Calendar ID="Calendar1" runat="server" SelectedDate='<%# Bind("DatumNarozeni") %>'></asp:Calendar></td>-->
<td>
<asp:TextBox ID="DatumNarozeniTextBox" runat="server" Text='<%# Bind("DatumNarozeni") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*"
ControlToValidate="DatumNarozeniTextBox"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="DatumNarozeniTextBox" ErrorMessage="Neplatne datum"
onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td>
Adresa:
</td>
<td>
<asp:TextBox ID="AdresaTextBox" runat="server" TextMode="MultiLine" Width="400px"
Height="100px" Text='<%# Bind("Adresa") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*"
ControlToValidate="AdresaTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Vlozit" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Zrusit"
OnClientClick="javascript: return confirm('Opravdu chce te zrusit<');" />
</insertitemtemplate>
</my:MyFormView>
</asp:Content>
using System;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// podle parametru v queryStringu urcit rezim komponenty FormView
if (!this.IsPostBack)
{
if (String.IsNullOrEmpty(Request.QueryString["id"]))
{
FormView1.DefaultMode = FormViewMode.Insert;
}else
{
FormView1.DefaultMode = FormViewMode.Edit;
}
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
DateTime d;
args.IsValid = DateTime.TryParse(args.Value, out d);
}
}
}
|