Hi telldurges,
Please refer below sample.
HTML
<div id="page-wrapper1">
<div class="white-box">
<div class="row button-box m-t-10 text-center">
<asp:LinkButton ID="btnUpdatePeriod" Text="Update" OnClick="btnUpdatePeriod_Click"
CssClass="global btn btn-outline btn-info " runat="server" CausesValidation="False"><i class="mdi mdi-update"></i> Update</asp:LinkButton>
</div>
<div class="table table-responsive" id="myTablePeriod">
<asp:ScriptManager ID="src" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="upnl1" runat="server">
<ContentTemplate>
<table id="myTable_k" class="table table-striped table-bordered">
<thead>
<tr>
<th>
SNo.
</th>
<th>
Period
</th>
<th>
Time
</th>
<th style="display: none">
<div class="checkbox checkbox-info m-0">
<asp:CheckBox ID="chkaddall" runat="server" />
<label class="col-md-12 ">
<strong>Set</strong>
</label>
</div>
</th>
</tr>
</thead>
<tbody>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Repeater ID="rpt_TeacherDetails" runat="server">
<ItemTemplate>
<tr id="ItemRow2">
<td>
<%# Container.ItemIndex + 1 %>
</td>
<td>
<asp:Label ID="lblPeriods" runat="server" Text='<%# Eval("Periods") %>' />
</td>
<td>
<asp:TextBox ID="txtTime" CssClass="form-control input-sm" runat="server" Text='<%# Eval("Time") %>'></asp:TextBox>
</td>
<td style="display: none">
<div class="checkbox checkbox-info m-0">
<asp:CheckBox ID="chkstatus" Text=" " runat="server" Checked='<%# Eval("Status").ToString() == "True" %>'
Required="true" Visible="false" />
</div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</tbody>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
Namespaces
C#
using System.Data;
using System.Globalization;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("Periods", typeof(string)),
new DataColumn("Time", typeof(string)),
new DataColumn("Status", typeof(string)) });
dt.Rows.Add("2", "7:30 AM-8:10 AM");
dt.Rows.Add("3", "7:30 AM-8:10 AM");
dt.Rows.Add("4", "8:50 AM-9:30 AM");
dt.Rows.Add("6", "9:30 AM-10:10 AM");
dt.Rows.Add("7", "10:10 AM-10:50 AM");
dt.Rows.Add("8", "10:50 AM-11:30 AM");
dt.Rows.Add("9", "11:30 AM-12:10 AM");
dt.Rows.Add("10", "12:10 AM-12:50 AM");
dt.Rows.Add("11", "12:50 AM-1:30 AM");
rpt_TeacherDetails.DataSource = dt;
rpt_TeacherDetails.DataBind();
}
}
protected void btnUpdatePeriod_Click(object sender, EventArgs e)
{
CultureInfo culture = new CultureInfo("en-US");
for (int i = 0; i < rpt_TeacherDetails.Items.Count - 1; i++)
{
TextBox txtPrevious = (TextBox)rpt_TeacherDetails.Items[i].FindControl("txtTime") as TextBox;
TextBox txtCurrent = (TextBox)rpt_TeacherDetails.Items[i + 1].FindControl("txtTime") as TextBox;
DateTime toTimePrevious = Convert.ToDateTime(txtPrevious.Text.Split('-')[1], culture);
DateTime fromTimeCurrent = Convert.ToDateTime(txtCurrent.Text.Split('-')[0], culture);
if (toTimePrevious > fromTimeCurrent)
{
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", " alert('Please enter correct time');", true);
break;
}
}
}