Here is what I am trying to do
Store Reservation data
Create a time table based on a date selected
Populate time table will reservations that are for date selected. for empty slots, display a slot open.
Here is what I have tried thus far
ERD
After inserting reservation data and querying all selected data for November 11th 2017
Displaying result for date is asp.net
What I would like to do
Have the schedule time table have slots starting from 6:00am and go
to 7:00pm. Go by intervals as provided by the following image below.
Be able to add reservations to empty slots using.
Be able to view details of current slots (only player names)
I have included my current code for the aspx file and the aspx.cs file below. Any help or guidance would be greatly appreciated. Thank you for your time.
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="MakeReservation.aspx.cs" Inherits="ClubBAIST.CBS.UI.MakeReservation" %>
<%--<%# Import Namespace="ClubBAIST.CBS.UI"%>--%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblDate" runat="server" Text="Date: "></asp:Label>
<asp:TextBox ID="tbxDate" runat="server"></asp:TextBox>
<%-- Expand/Hide Calendar --%>
<asp:Button ID="BtnCalendar" runat="server" OnClick="BtnCalendar_Click" Height="25px" Width="25px" Text="+" />
<%-- Handle customer selection via calendar control --%>
<asp:Calendar ID="calCalendar" runat="server" Visible="False" OnSelectionChanged="calCalendar_SelectionChanged" BackColor="White" BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="190px" NextPrevFormat="FullMonth" Width="350px">
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
<TodayDayStyle BackColor="#CCCCCC" />
</asp:Calendar>
<%-- Drop down for days of the week --%>
<asp:Label ID="lblDayOfWeek" runat="server" Text="Day Of Week: "></asp:Label>
<asp:DropDownList ID="ddlDayOfWeek" runat="server">
<asp:ListItem Text="Sunday" Value="Sunday"></asp:ListItem>
<asp:ListItem Text="Monday" Value="Monday"></asp:ListItem>
<asp:ListItem Text="Tuesday" Value="Tuesday"></asp:ListItem>
<asp:ListItem Text="Wednesday" Value="Wednesday"></asp:ListItem>
<asp:ListItem Text="Thursday" Value="Thursday"></asp:ListItem>
<asp:ListItem Text="Friday" Value="Friday"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="GetTeeTimes" runat="server" Text="Find Tee Times" />
<br />
<asp:Table ID="TeeTimesTable" runat="server">
</asp:Table>
<asp:GridView ID="gvTeeTime" runat="server" OnSelectedIndexChanged="gvTeeTime_SelectedIndexChanged">
</asp:GridView>
<br />
<div>
<asp:Table ID="BookingTable" runat="server" Visible="false">
<asp:TableRow>
<asp:TableHeaderCell>
<h3>Book Tee Time</h3>
</asp:TableHeaderCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Date:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="Date" TextMode="Date" runat="server"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Time:
</asp:TableCell>
<asp:TableCell>
Hour:
<asp:DropDownList ID="Hour" runat="server">
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
</asp:DropDownList>
Minute:<asp:DropDownList ID="Minute" runat="server">
<asp:ListItem>00</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>37</asp:ListItem>
<asp:ListItem>45</asp:ListItem>
<asp:ListItem>52</asp:ListItem>
</asp:DropDownList>
AMorPM
<asp:DropDownList ID="AMorPM" AutoPostBack="true" OnSelectedIndexChanged="AMorPM_SelectedIndexChanged" runat="server">
<asp:ListItem>AM</asp:ListItem>
<asp:ListItem>PM</asp:ListItem>
</asp:DropDownList><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Number of Players:
</asp:TableCell>
<asp:TableCell>
<asp:RadioButtonList OnSelectedIndexChanged="NumberOfPlayers_SelectedIndexChanged" ID="NumberOfPlayers" runat="server" RepeatDirection="Horizontal" AutoPostBack="True">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:RadioButtonList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Member Type :
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList
ID="MemberTypeDDL"
runat="server">
<asp:ListItem> </asp:ListItem>
<asp:ListItem Text="Gold" Value="1"> </asp:ListItem>
<asp:ListItem Text="Silver" Value="2"> </asp:ListItem>
<asp:ListItem Text="Bronze" Value="3"> </asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
MemberNumber:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberNumber" runat="server" Enabled="True"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 1:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName1" runat="server" Enabled="true"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 2:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName2" runat="server" Enabled="false"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 3:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName3" runat="server" Enabled="false"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 4:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName4" runat="server" Enabled="false"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Number Of Carts:
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList
ID="NoOfCartsDDL"
runat="server">
<asp:ListItem> </asp:ListItem>
<asp:ListItem Text="None" Value="0"> </asp:ListItem>
<asp:ListItem Text="One" Value="1"> </asp:ListItem>
<asp:ListItem Text="Two" Value="2"> </asp:ListItem>
<asp:ListItem Text="Three" Value="3"> </asp:ListItem>
<asp:ListItem Text="Four" Value="4"> </asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableFooterRow>
<asp:TableCell>
<asp:Button ID="BookTeeTime" runat="server" OnClick="BookTeeTime_Click" Text="Book Tee Time" />
</asp:TableCell>
</asp:TableFooterRow>
</asp:Table>
</div>
<asp:Label ID="Message" runat="server" Text=""></asp:Label><br /><br />
</form>
</body>
</html>
ASPX.CS
using ClubBAIST.CBS.Domain;
using ClubBAIST.CBS.TechnicalServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/// <summary>
/// Namespace for all UI for Club BAIST
/// </summary>
namespace ClubBAIST.CBS.UI
{
/// <summary>
/// Interacts with the Controller class CBS to create a reservation
/// </summary>
public partial class MakeReservation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}//eom
/// <summary>
/// When user changes selection, whether via DDL or Calendar, update the Textbox field.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void calCalendar_SelectionChanged(object sender, EventArgs e)
{
tbxDate.Text = calCalendar.SelectedDate.ToShortDateString();
ddlDayOfWeek.Text = calCalendar.SelectedDate.DayOfWeek.ToString();
BookingTable.Visible = true;
Date.Text = calCalendar.SelectedDate.ToShortDateString();
calCalendar.Visible = false;
//ViewReservationSheet
//ClubBAISTController TeeTimeDirector = new ClubBAISTController();
TeeTimes TeeTimesManager = new TeeTimes();
DateTime ttDate = Convert.ToDateTime( tbxDate.Text);
gvTeeTime.DataSource = TeeTimesManager.GetTeeTime(ttDate);
gvTeeTime.DataBind();
//TeeTime TeeTimeManager = new TeeTime();
}//eom
/// <summary>
/// Makes the Calendar appear upon expanding
/// </summary>
protected void BtnCalendar_Click(object sender, EventArgs e)
{
calCalendar.Visible = true;
}//eom
protected void NumberOfPlayers_SelectedIndexChanged(object sender, EventArgs e)
{
if (NumberOfPlayers.SelectedIndex == 0)
{
MemberName1.Enabled = true;
MemberName2.Enabled = false;
MemberName3.Enabled = false;
MemberName4.Enabled = false;
MemberName2.Text = "";
MemberName3.Text = "";
MemberName4.Text = "";
}
else if (NumberOfPlayers.SelectedIndex == 1)
{
MemberName1.Enabled = true;
MemberName2.Enabled = true;
MemberName3.Enabled = false;
MemberName4.Enabled = false;
MemberName3.Text = "";
MemberName4.Text = "";
}
else if (NumberOfPlayers.SelectedIndex == 2)
{
MemberName1.Enabled = true;
MemberName2.Enabled = true;
MemberName3.Enabled = true;
MemberName4.Enabled = false;
MemberName4.Text = "";
}
else
{
MemberName1.Enabled = true;
MemberName2.Enabled = true;
MemberName3.Enabled = true;
MemberName4.Enabled = true;
}
}
protected void AMorPM_SelectedIndexChanged(object sender, EventArgs e)
{
Hour.Items.Clear();
if (AMorPM.SelectedIndex == 0)
{
Hour.Items.Add("6");
Hour.Items.Add("7");
Hour.Items.Add("8");
Hour.Items.Add("9");
Hour.Items.Add("10");
Hour.Items.Add("11");
}
else
{
Hour.Items.Add("12");
Hour.Items.Add("1");
Hour.Items.Add("2");
Hour.Items.Add("3");
Hour.Items.Add("4");
Hour.Items.Add("5");
Hour.Items.Add("6");
Hour.Items.Add("7");
Hour.Items.Add("8");
}
}
protected void gvTeeTime_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void BookTeeTime_Click(object sender, EventArgs e)
{
int hours = int.Parse(Hour.SelectedItem.Text);
int minutes = int.Parse(Minute.SelectedItem.Text);
if (AMorPM.SelectedItem.Text == "PM" && hours != 12)
hours += 12;
string datetime = Date.Text;
datetime += " " + hours.ToString() + ":" + minutes.ToString();
TeeTime NewTeeTime;
DateTime DateT = DateTime.Parse(datetime);
try
{
NewTeeTime = new TeeTime(DateT, DateT, Convert.ToInt32(MemberNumber.Text), MemberName1.Text, MemberName2.Text, MemberName3.Text, MemberName4.Text, Convert.ToInt32(NumberOfPlayers.SelectedValue), Convert.ToInt32(NoOfCartsDDL.SelectedValue),Convert.ToInt32(MemberTypeDDL.SelectedValue));
}
catch (Exception)
{
Message.Text = "Some of your fields are incorrect";
return;
}
ClubBAISTController RequestHandler = new ClubBAISTController();
if (RequestHandler.ReserveTeeTime(NewTeeTime))
{
Message.Text = "Reservation was successfuly made.";
//update teeTimes
TeeTimes TeeTimesManager = new TeeTimes();
DateTime ttDate = Convert.ToDateTime(tbxDate.Text);
gvTeeTime.DataSource = TeeTimesManager.GetTeeTime(ttDate);
gvTeeTime.DataBind();
}
else
{
Message.Text = "Reservation could not be made.";
}
}
}//eoc
}//eon
Related
Is there a way to generate labels based on how many user entry's there are in a database and print the database information to the labels on page load.
I have attempted to do this by binding the data but i found i can only do this in a grid format and i don't want a grid.
What i am trying to create overall is a survey in which the questions are stored in the database and displayed on the labels. I want someone to be able to add a question to the database and a label to be automatically generated for it displaying the question.
I am able to get my desired effect but i have added labels and written the questions on them manually. If anyone can please help or advise if it can be done it would be much appreciated. Thank you in advanced.
Here is what i have so far:
<h1> </h1>
<h1>PaaS Assured Server Test</h1>
<div class="row">
<div class="col-md-6">
<h2>
<asp:Label ID="lblmsg" runat="server"></asp:Label>
<asp:Panel ID="BugPanel1" runat="server" BorderColor="#FFFF99" BackColor="#FFFF99" Visible="False">
<asp:Label ID="Label4" runat="server" Text="You have informed us of an error." ForeColor="Black"></asp:Label>
<br /><asp:Label ID="Label3" runat="server" Text="Please advise of serverity. 1 - highest 5 - lowest:" ForeColor="Black"></asp:Label>
<asp:DropDownList ID="SeverityList1" runat="server" AutoPostBack="True">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
<br /><asp:Label ID="Label5" runat="server" Text="Who shall be notified of the error:" ForeColor="Black"></asp:Label>
<asp:DropDownList ID="NotifyList1" runat="server" DataSourceID="SqlDataSource2" AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT [UserName] FROM [AspNetUsers]"></asp:SqlDataSource>
<br /><asp:Label ID="Label6" runat="server" Text="Would you like a copy emailed to yourself?" ForeColor="Black"></asp:Label>
<asp:RadioButtonList ID="EmailRadio1" runat="server" AutoPostBack="True" RepeatDirection="Horizontal">
<asp:ListItem Value="True" Text="Yes">Yes</asp:ListItem>
<asp:ListItem Value="True" Text="Yes">No</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="BugButton" runat="server" Text="File Bug and Generate Report" CausesValidation="False" OnClick="BugButton_Click" />
</asp:Panel>
</h2>
<h2>Provisioning</h2>
<hr />
<asp:Panel ID="FormPanel1" runat="server" BackColor="#F4F4F4">
<asp:Panel ID="HeadPanel1" runat="server" BackColor="#E4E4E4" BorderColor="#999999" Font-Bold="True" ForeColor="#000066" Font-Underline="True">
<h3>Page View</h3>
</asp:Panel>
<asp:RequiredFieldValidator ID="Radio1Validator" runat="server" ErrorMessage="Error: Please select an option:" ControlToValidate="Radio1" SetFocusOnError="True" ForeColor="Red"></asp:RequiredFieldValidator>
<p />
<asp:Label ID="PALabel1" runat="server" Text="Does your screen look similar to the image displayed ?"></asp:Label>
<asp:ImageButton ID="ImageButton1" runat="server" Height="20px" ImageUrl="~/Image/PrintScreen/Info.jpg" OnClick="ImageButton1_Click" Width="21px" CausesValidation="False" /><br/>
<asp:RadioButtonList ID="Radio1" runat="server" AutoPostBack="True" RepeatDirection="Horizontal">
<asp:ListItem Value="True" Text="Yes">Yes</asp:ListItem>
<asp:ListItem Text="No" Value="False">No</asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="PAPanel1" runat="server">
<asp:Label ID="Label1" runat="server" ForeColor="#000099" Text="Provide further details:"></asp:Label>
<asp:TextBox ID="PAText1" runat="server" BorderColor="Silver" CssClass="form-control"></asp:TextBox>
</asp:Panel>
<p />
<asp:RequiredFieldValidator ID="Radio2Validator" runat="server" ControlToValidate="Radio2" ErrorMessage="Error: Please select an option:" ForeColor="Red"></asp:RequiredFieldValidator>
<p />
<asp:Label ID="PALabel2" runat="server" Text="In "Server Name" is virtual pre-selected?"></asp:Label>
<asp:ImageButton ID="ImageButton4" height="20px" runat="server" Width="21px" CausesValidation="False" ImageUrl="~/Image/PrintScreen/Info.jpg" OnClick="ImageButton4_Click" />
<br/>
<asp:RadioButtonList ID="Radio2" runat="server" AutoPostBack="True" RepeatDirection="Horizontal">
<asp:ListItem Value="True" Text="Yes">Yes</asp:ListItem>
<asp:ListItem Text="No" Value="False">No</asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="PAPanel2" runat="server">
<asp:Label ID="Label2" runat="server" Text="Provide further details:" ForeColor="#000099"></asp:Label>
<asp:TextBox ID="PAText2" runat="server" CssClass="form-control" BorderColor="Silver" ></asp:TextBox>
</asp:Panel>
<asp:Panel ID="HeadPanel2" runat="server" BackColor="#E4E4E4" BorderColor="#999999" Font-Bold="True" ForeColor="#000066" Font-Underline="True">
<h3>Form details</h3>
</asp:Panel>
<asp:Panel ID="SubHead1" runat="server" BackColor="#F3F3F3" BorderColor="#999999" Font-Bold="False" ForeColor="#003399" Font-Underline="True" Font-Italic="True" Font-Size="Smaller">
<h4>Request Details</h4>
</asp:Panel>
<asp:Panel ID="SubHead2" runat="server" BackColor="#F3F3F3" BorderColor="#999999" Font-Bold="False" ForeColor="#003399" Font-Underline="True" Font-Italic="True" Font-Size="Smaller">
<h4>Server Location</h4>
</asp:Panel>
<asp:Panel ID="SubHead3" runat="server" BackColor="#F3F3F3" BorderColor="#999999" Font-Bold="False" ForeColor="#003399" Font-Underline="True" Font-Italic="True" Font-Size="Smaller">
<h4>Product and Support Details</h4>
</asp:Panel>
<asp:Panel ID="SubHead4" runat="server" BackColor="#F3F3F3" BorderColor="#999999" Font-Bold="False" ForeColor="#003399" Font-Underline="True" Font-Italic="True" Font-Size="Smaller">
<h4>Server Configuration</h4>
</asp:Panel>
<asp:Label ID="PALabel3" runat="server" Text="What operating system are you testing?"></asp:Label>
<asp:ImageButton ID="ImageButton3" runat="server" Height="20px" ImageUrl="~/Image/PrintScreen/Info.jpg" OnClick="ImageButton1_Click" Width="21px" CausesValidation="False" /><br/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please select the server you are testing:" ControlToValidate="Radio3" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RadioButtonList ID="Radio3" runat="server" AutoPostBack="True" RepeatDirection="Horizontal">
<asp:ListItem Value="Windows 2008 Server R2" Text="Windows 2008 Server R2">Windows 2008 Server R2</asp:ListItem>
<asp:ListItem Value="Windows 2012 Server R2" Text="Windows 2012 Server R2">Windows 2012 Server R2</asp:ListItem>
<asp:ListItem Value="RHEL" Text="RHEL">RHEL</asp:ListItem>
</asp:RadioButtonList>
<p /> <p />
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Submit"/>
<p />
</asp:Panel>
</div>
<div class="col-md-6">
<h2> </h2>
<h2>Information Viewer <asp:Image ID="LrgInfoImage" runat="server" ImageUrl="~/Image/PrintScreen/Info.jpg" Height="21px" Width="24px" />
  <asp:Button ID="Button2" runat="server" Text="View test history" BorderColor="#ECECFF" BorderStyle="Ridge" CssClass="btn" Font-Underline="True" ForeColor="#0066FF" Height="32px" OnClick="Button2_Click" Width="177px" CausesValidation="False" />
</h2> <hr />
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View0" runat="server">
<div style="overflow-x:auto;width:600px" class="fixed">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="PAssuredId" DataSourceID="SqlDataSource1" AllowSorting="True" BorderColor="#F4F4F4" ForeColor="#000066" GridLines="Horizontal" Width="56%" HorizontalAlign="Center">
<AlternatingRowStyle BackColor="#F4F4FF" BorderColor="Black" ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="PAssuredId" HeaderText="Test ID" InsertVisible="False" ReadOnly="True" SortExpression="PAssuredId" NullDisplayText="INVALID TEST" ItemStyle-BackColor="#F0F0FF" />
<asp:BoundField DataField="Date" HeaderText="Date/ Time" SortExpression="Date" />
<asp:BoundField DataField="UserName" HeaderText="User" SortExpression="UserName" NullDisplayText="INVALID TEST" />
<asp:BoundField DataField="Platform" HeaderText="Platform" SortExpression="Platform" NullDisplayText="User did not select platform" />
<asp:CheckBoxField DataField="VirtualPreselect" HeaderText="Virtual" SortExpression="VirtualPreselect" />
<asp:CheckBoxField DataField="DetsAccurate" HeaderText="Details ok?" SortExpression="DetsAccurate" />
<asp:CheckBoxField DataField="ScreenSame" HeaderText="Correct form?" SortExpression="ScreenSame" />
<asp:BoundField DataField="No1" HeaderText="Error 1" SortExpression="No1" NullDisplayText="No error found" ReadOnly="True" />
<asp:BoundField DataField="No2" HeaderText="Error 2" SortExpression="No2" NullDisplayText="No error found" />
<asp:BoundField DataField="No3" HeaderText="Error 3" SortExpression="No3" NullDisplayText="No error found" />
<asp:BoundField DataField="No4" HeaderText="Error 4" SortExpression="No4" NullDisplayText="No error found" />
<asp:BoundField DataField="No5" HeaderText="Error 5" SortExpression="No5" NullDisplayText="No error found" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT PaaSAssuredServer.PAssuredId, PaaSAssuredServer.Date, AspNetUsers.UserName, PaaSAssuredServer.Platform, PaaSAssuredServer.VirtualPreselect, PaaSAssuredServer.DetsAccurate, PaaSAssuredServer.ScreenSame, PaaSAssuredServer.No1, PaaSAssuredServer.No2, PaaSAssuredServer.No3, PaaSAssuredServer.No4, PaaSAssuredServer.No5 FROM PaaSAssuredServer INNER JOIN AspNetUsers ON PaaSAssuredServer.UserId = AspNetUsers.Id ORDER BY PaaSAssuredServer.Date DESC"></asp:SqlDataSource>
</asp:View>
<asp:View ID="View1" runat="server">
<asp:Image ID="ScreenImge" runat="server" Height="600px" ImageUrl="~/Image/PrintScreen/PassTest1.jpg" Width="600px" />
</asp:View>
<asp:View ID="View2" runat="server">
<asp:Image ID="Image1" runat="server" Height="105px" ImageUrl="~/Image/PrintScreen/ServerType.jpg" Width="446px" />
</asp:View>
<asp:View ID="View3" runat="server">
<asp:Image ID="Image2" runat="server" ImageUrl="~/Image/PrintScreen/ServerType.jpg" Height="105px" Width="446px" />
</asp:View>
</asp:MultiView>
</div>
</div>
</asp:Content>
Here is the code behind :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Windows.Forms;
using Microsoft.AspNet.Identity;
namespace IRISTest
{
public partial class PaaSAssuredServer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Radio1.SelectedValue == "False")
{
PAPanel1.Visible = true;
}
else
{
PAPanel1.Visible = false;
}
if (Radio2.SelectedValue == "False")
{
PAPanel2.Visible = true;
}
else
{
PAPanel2.Visible = false;
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
MultiView1.ActiveViewIndex = 1;
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 0;
}
protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
{
MultiView1.ActiveViewIndex = 3;
}
protected void Submit(object sender, EventArgs e)
{
{
string message = "I can confirm the following:" + Environment.NewLine + "It is " + Radio1.SelectedValue + " that my screen matches that displayed in the image. " + Environment.NewLine +
"It is:" + Radio2.SelectedValue + " that my default Server Name is set to Virtual. " + Environment.NewLine +
"I have follwed the steps accurately and provided all requested information/ further details to enable further investigation" + Environment.NewLine +
"On hitting sumbit I am confirming that I have perfomed this test and the provided information is accurate to my knowledge.";
string caption = "Confirmation:";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
MessageBoxIcon icon = MessageBoxIcon.Information;
MessageBoxDefaultButton defaultbutton = MessageBoxDefaultButton.Button2;
DialogResult result;
result = MessageBox.Show(message, caption, buttons, icon, defaultbutton);
if (result == DialogResult.Yes)
{
Int32 newProdID = 0;
var userId = User.Identity.GetUserId();
var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("INSERT INTO [PaaSAssuredServer] ([VirtualPreselect], [No1], [No2], [ScreenSame], [Date], [UserId], [Platform]) VALUES ( #VirtualPreselect, #No1, #No2, #ScreenSame, #Date, #UserId, #Platform);" + "SELECT CAST(scope_identity() AS int)");
//cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("#ScreenSame", Radio1.SelectedItem.Value);
cmd.Parameters.AddWithValue("#VirtualPreselect", Radio2.SelectedItem.Value);
cmd.Parameters.AddWithValue("#No1", PAText1.Text);
cmd.Parameters.AddWithValue("#No2", PAText2.Text);
cmd.Parameters.AddWithValue("#Date", DateTime.Now);
cmd.Parameters.AddWithValue("#UserId", userId);
cmd.Parameters.AddWithValue("#Platform", Radio3.SelectedItem.Value);
//cmd.Parameters.AddWithValue("#UserId", 0);
//cmd.Parameters["#UserId"].Direction = ParameterDirection.InputOutput;
connection.Open();
try
{
newProdID = (Int32)cmd.ExecuteScalar();
//int UserId = (int)cmd.Parameters["#UserId"].Value;
//cmd.ExecuteNonQuery();
//var rowCount = cmd.ExecuteScalar();
lblmsg.Text = "You have completed and recorded the test Sucessfully " + Environment.NewLine +
"Your test number is: " + newProdID;
lblmsg.ForeColor = System.Drawing.Color.Green;
}
catch (SqlException sqlEx)
{
lblmsg.Text = sqlEx.Message;
lblmsg.ForeColor = System.Drawing.Color.Red;
}
finally
{
connection.Close();
}
if (PAText1.Text == "0")
{
BugPanel1.Visible = true;
}
else
{
BugPanel1.Visible = false;
}
if (PAText2.Text == "0")
{
BugPanel1.Visible = true;
}
else
{
BugPanel1.Visible = false;
}
}
}
}
}
protected void BugButton_Click(object sender, EventArgs e)
{
Int32 newProdID1 = 0;
var userId = User.Identity.GetUserId();
var BugTest = true;
var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("INSERT INTO [BugRep] ([Bug], [Serverity], [CorrName], [UserId]) VALUES (#Bug, #Serverity, #CorrName, #UserId);" + "SELECT CAST(scope_identity() AS int)");
//cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("#Serverity", SeverityList1.SelectedItem.Value);
cmd.Parameters.AddWithValue("#CorrName", NotifyList1.SelectedItem.Value);
cmd.Parameters.AddWithValue("#Bug", BugTest);
cmd.Parameters.AddWithValue("#UserId", userId);
cmd.Parameters.AddWithValue("#Platform", Radio3.SelectedItem.Value);
//cmd.Parameters.AddWithValue("#UserId", 0);
//cmd.Parameters["#UserId"].Direction = ParameterDirection.InputOutput;
connection.Open();
try
{
newProdID1 = (Int32)cmd.ExecuteScalar();
//int UserId = (int)cmd.Parameters["#UserId"].Value;
//cmd.ExecuteNonQuery();
//var rowCount = cmd.ExecuteScalar();
lblmsg.Text = "You have reported the bug sucessfully and" + NotifyList1.SelectedItem.Value + "has been informed." + Environment.NewLine +
"Your test number is: " + newProdID1;
lblmsg.ForeColor = System.Drawing.Color.Green;
}
catch (SqlException sqlEx)
{
lblmsg.Text = sqlEx.Message;
lblmsg.ForeColor = System.Drawing.Color.Red;
}
finally
{
connection.Close();
}
}
}
}
}
You are on the right track to use data binding. If you want to have more control over the HTML that is generated, you can use a Repeater control. This way, you can specify templates for the items you want to display.
The following sample shows a Repeater. In the ItemTemplate, a HiddenField stores the question id and a Label shows the text. When the page is requested, the items are retrieved from a database (the sample uses test data) and bound to the Repeater. I've also added a dropdown in the ItemTemplate so that the user can select an answer. Upon clicking the Save button, the values are retrieved from the controls in the items of the Repeater.
ASPX
<asp:Repeater ID="rpt" runat="server">
<ItemTemplate>
<p>
<asp:HiddenField ID="hiddenId" runat="server" Value='<%# Eval("Id") %>' />
<asp:Label ID="lblQuestion" runat="server" Text='<%# Eval("Text") %>' />
<asp:DropDownList ID="ddlAnswer" runat="server">
<asp:ListItem Text="1" />
<asp:ListItem Text="2" />
<asp:ListItem Text="3" />
</asp:DropDownList>
</p>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
Code Behind
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var questions = GetQuestions();
rpt.DataSource = questions;
rpt.DataBind();
}
}
private IEnumerable<Question> GetQuestions()
{
// Load questions from database
// Setting up some sample data for this sample
var lst = new List<Question>();
return Enumerable.Range(1, 5).Select(x => new Question() { Id = x, Text = "Question " + x.ToString() });
}
protected void btnSave_Click(object sender, EventArgs e)
{
var dictAnswers = GetValuesFromRepeater();
// Save answers to database
}
private IDictionary<int, int> GetValuesFromRepeater()
{
var dict = new Dictionary<int, int>();
foreach (RepeaterItem item in rpt.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
var id = int.Parse(((HiddenField)item.FindControl("hiddenId")).Value);
var answer = int.Parse(((DropDownList)item.FindControl("ddlAnswer")).Text);
dict.Add(id, answer);
}
}
return dict;
}
}
public class Question
{
public int Id { get; set; }
public string Text { get; set; }
}
Please note that when retrieving the values from the repeater, the controls have to be found by their id using the FindControl method.
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand ("select fields from database", con);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
foreach (DataRow dr in DataSet.Tables[0].Rows){
Label lbl = new Label();
lbl.Text = dr["column"].ToString() + ":";
TextBox txt = new TextBox();
txt.ID = "txt" + dr["id"].ToString();
}
You have to push it into !IsPostBack
On saving you have to take all IDs into some array or list, and use foreach array:
foreach (int id in id_array){
command.Parameters.AddWithValue("#"+param+id.ToString(), (TextBox)(Page.FindControlById("txt"+id.ToString())).Text);
}
But you also have to think about your sql_query (in code-behind or stored procedure, make it responsive, depending on params number).
Hope it helps
I have a web page that has developed an issue with only some of the dropdownlists. As indicated autopostback = true and yes I'm accounting for the !postback.
Line of Business, Director and Agent all post back without issue but the Senior Manager and Manager postback with the first value on the list regardless of selection.
here is the asp
<asp:TableRow>
<asp:TableCell CssClass="tc1" Width="17%">
<asp:Label ID="lblLob" runat="server">Line Of Business: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbLoB" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvLoB" runat="server" ControlToValidate="cmbLoB" InitialValue="0" ErrorMessage="Please select a Line of Business"></asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="tcRange" CssClass="tc1" runat="server" Width="15%">
<asp:Label ID="lblDateRange" runat="server">Report Range: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbDateRange" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1"><asp:Label ID="lblStartDate" runat="server" Text="Start Date: "></asp:Label></asp:TableCell>
<asp:TableCell CssClass="tc2"><asp:TextBox ID="txtStartDate" runat="server" AutoPostBack="true"></asp:TextBox><asp:CalendarExtender
ID="calStartDate" runat="server" TargetControlID="txtStartDate" Format="yyyy-MM-dd">
</asp:CalendarExtender>
</asp:TableCell>
<asp:TableCell CssClass="tc1"><asp:Label ID="lblEndDate" runat="server" Text="End Date: "></asp:Label></asp:TableCell>
<asp:TableCell CssClass="tc2"><asp:TextBox ID="txtEndDate" runat="server" AutoPostBack="true"></asp:TextBox><asp:CalendarExtender
ID="calEndDate" runat="server" TargetControlID="txtEndDate" Format="yyyy-MM-dd"></asp:CalendarExtender>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1" Width="17%">
<asp:Label ID="lblDirector" runat="server">Senior Leader: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbDirector" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
<asp:TableCell CssClass="tc1" Width="17%" ID="tdlblAggregate" runat="server" Visible="false">
<asp:Label ID="lblAggregate" runat="server">Aggregation Level: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1" ID="tdcmbAggregate" runat="server" Visible="false">
<asp:DropDownList ID="cmbAggregate" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect">
<asp:ListItem Value="LoB" Text="Segment"></asp:ListItem>
<asp:ListItem Value="SM" Text="Senior Manager"></asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1">
<asp:Label ID="lblSManager" Visible="true" runat="server">Senior Manager: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbSManager" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1">
<asp:Label ID="lblManager" Visible="true" runat="server">Manager: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbManager" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1">
<asp:Label ID="lblAgent" Visible="true" runat="server">Associate/Specialist: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbAgent" runat="server" AutoPostBack="true" Visible="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
And the code behind:
DataTable SLTSelectDistinct = SLTSelect.DefaultView.ToTable(true, "sltID", "sltName");
DataView sltSelect = new DataView(SLTSelectDistinct);
DataRow sltRow = SLTSelectDistinct.NewRow();
sltRow[0] = "0";
sltRow[1] = "-- Please Select --";
SLTSelectDistinct.Rows.Add(sltRow);
sltSelect.Sort = "sltName";
cmbDirector.DataValueField = "sltID";
cmbDirector.DataTextField = "sltName";
cmbDirector.DataSource = sltSelect;
cmbDirector.DataBind();
DataTable SMSelectDistinct = SMSelect.DefaultView.ToTable(true, "smID", "smName");
DataView smSelect = new DataView(SMSelectDistinct);
DataRow smRow = SMSelectDistinct.NewRow();
smRow[0] = "0";
smRow[1] = "-- Please Select --";
SMSelectDistinct.Rows.Add(smRow);
smSelect.Sort = "smName";
cmbSManager.DataValueField = "smID";
cmbSManager.DataTextField = "smName";
cmbSManager.DataSource = smSelect;
cmbSManager.DataBind();
DataTable MSelectDistinct = MSelect.DefaultView.ToTable(true, "mID", "mName");
DataView mSelect = new DataView(MSelectDistinct);
DataRow mRow = MSelectDistinct.NewRow();
mRow[0] = "0";
mRow[1] = "-- Please Select --";
MSelectDistinct.Rows.Add(mRow);
mSelect.Sort = "mName";
cmbManager.DataValueField = "mID";
cmbManager.DataTextField = "mName";
cmbManager.DataSource = mSelect;
cmbManager.DataBind();
DataTable ASelectDistinct = LoBSelect.DefaultView.ToTable(true, "C_AGT", "aName");
DataView aSelect = new DataView(ASelectDistinct);
DataRow aRow = ASelectDistinct.NewRow();
aRow[0] = "0";
aRow[1] = "-- Please Select --";
ASelectDistinct.Rows.Add(aRow);
aSelect.Sort = "aName";
cmbAgent.DataValueField = "C_AGT";
cmbAgent.DataTextField = "aName";
cmbAgent.DataSource = aSelect;
cmbAgent.DataBind();
It is probably that you have 0 as the value of one of your actual options as well so when the page refreshes the selected value of the dropdown is 0 which also happens to be the value of the default "Select One" option.
I have a website that has a code-behind file and a separate class that has a function that takes a long time to complete.
What I want is to show some information to the visitor when the function passes a string.
I use a delegate to send a string back to the code-behind like this:
public event Feedback feedbackInfo;
public EventArgs e = null;
public delegate void Feedback(String message, bool info);
So in my function I can use FeedbackInfo("message", true); which is received by the code-behind function setFeedback:
public void example() {
new Thread(delegate()
{
crypto = new EncryptNoLibraries(#"C:\Users\Robbie\TestDES\New Microsoft Visio Drawing.vsdx", #"C:\Users\Robbie\TestDES\New Microsoft Visio Drawing encrypted.vsdx");
crypto.feedbackInfo += new EncryptNoLibraries.Feedback(setFeedback);
object[] allArgs = { EncryptNoLibraries.CryptType.ENCRYPT, lstSleutels };
object args = allArgs;
crypto.DoCryptFile(args);
}).Start();
}
public void setFeedback(String message, bool info)
{
if (info)
{
if (!infoCell.Visible)
{
errorCell.Visible = false;
infoCell.Visible = true;
}
lblInfo.Text += String.Format("- {0}<br />", message);
}
else
{
if (!errorCell.Visible)
{
infoCell.Visible = false;
errorCell.Visible = true;
}
lblError.Text += String.Format("- {0}<br />", message);
}
}
This is my webpage:
<%# Page Title="Home" Async="true" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DESEncryptie._Default" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<script type="text/javascript">
function updater() {
__doPostBack('updatePanel', '');
}
</script>
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>DES encryptie/decryptie</h1>
</hgroup>
<p>
Kies simpelweg uw bestand. Vervolgens kiest u uw sleutel en de methode van encryptie of decryptie. Als laatste kiest u de taal waarmee u wilt werken (bijv. Java of .NET).
</p>
</div>
</section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<h3>Start hier:</h3>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Table runat="server" CssClass="tableStartHier">
<asp:TableRow>
<asp:TableCell>Bestand:</asp:TableCell>
<asp:TableCell>
<asp:FileUpload ID="bestand" runat="server" on />
<i>(Probleem: bestandsnamen kunnen te lang zijn)</i>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:CheckBox ID="DES" runat="server" Checked="true" TextAlign="Left"
Text="DES" OnCheckedChanged="DES_CheckedChanged" AutoPostBack="true" /></asp:TableCell>
<asp:TableCell><asp:CheckBox ID="ThreeDES" runat="server" Checked="false" TextAlign="Left"
Text="3DES" OnCheckedChanged="ThreeDES_CheckedChanged" AutoPostBack="true" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2">Sleutel:</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDES" runat="server" Visible="true">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel" runat="server" placeholder="Geef een sleutel" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDrieDES1" runat="server" Visible="false">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel1" runat="server" placeholder="Geef sleutel 1" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDrieDES2" runat="server" Visible="false">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel2" runat="server" placeholder="Geef sleutel 2" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDrieDES3" runat="server" Visible="false">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel3" runat="server" placeholder="Geef sleutel 3" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Taal:</asp:TableCell>
<asp:TableCell>
<asp:DropDownList ID="taal" runat="server" Width="75px">
<asp:ListItem Text=".NET" Value=".NET" />
<asp:ListItem Text=".NET Libraries" Value=".NETLib" />
<asp:ListItem Text="Java Libraries" Value="Java" />
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:Button id="encrypteer" Text="Encrypteer" runat="server" OnClientClick="setInterval(updater, 2500);" OnClick="encrypteer_Click" ToolTip="Encrypteer uw bestand" /></asp:TableCell>
<asp:TableCell><asp:Button id="decrypteer" runat="server" Text="Decrypteer" OnClick="decrypteer_Click" ToolTip="Decrypteer uw bestand" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell runat="server" ID="spinner" Visible="false">
<asp:Image ID="imgSpinner" runat="server" ImageUrl="~/Images/spinner.gif"/>Even geduld.
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ForeColor="Blue">
<asp:TableCell ID="infoCell" runat="server" ColumnSpan="2" Visible="false">
Informatieberichten tijdens het crypteren:<br />
<asp:Label ID="lblInfo" runat="server" Text="" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ForeColor="Red">
<asp:TableCell ID="errorCell" runat="server" ColumnSpan="2" Visible="false">
Foutberichten tijdens het crypteren:<br />
<asp:Label ID="lblError" runat="server" Text="" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
You can see I use a javascript to update my panel by postback every 2.5 seconds. The problem is that when the postback is triggered, the text in the label that should be update is lost.
Here are some images to illustrate. Before is how the page looks at first render and after is what is displayed after I push the encrypt button. Not all messages are displayed even after 2.5 seconds (they even disappear!).
Before:
After:
What am I doing wrong?
I guess this was my fault, I found a solution.
I added two static string variables holding the messages so far.
private static String infoMessages = "", errorMessages = "";
public void setFeedback(String message, bool info)
{
if (info)
{
if (!infoCell.Visible)
{
errorCell.Visible = false;
infoCell.Visible = true;
}
infoMessages += String.Format("- {0}<br />", message);
lblInfo.Text += infoMessages;
}
else
{
if (!errorCell.Visible)
{
infoCell.Visible = false;
errorCell.Visible = true;
}
errorMessages += String.Format("- {0}<br />", message);
lblError.Text += errorMessages;
}
}
I don't think ASP .Net web page objects persist between posts. They are recreated and populated from your session store.
In my code, I have a background operation that is global to the app. I was able to use some static members in the class to relay progress of the background task to users.
I used the ASP timer to get the postbacks:
The Timer1_Tick method has no code in it. Just a comment stating the PageLoad did the work related to showing progress.
Your case will be a bit tougher, since you can have a background task for each browser instance.
If you use a static member dictionary, keyed by session id, the background process can update the dictionary entry and Page_Load can update the user's screen.
Then there's the problem of sessions coming and going. How do you clean up such a dictionary?
Also, remember IIS tends to shut down the whole web site process after 20 minutes of no http requests.
[And while I was typing my verbose answer, you seem to have found it yourself. Good show!]
I am badly stuck on this problem and would appreciate any kinds of helps! I have to create a page where the user can add more rows by clicking a button. For example, I have the first row with 2 text boxes (name and birth dates), second row with the "Add Row" button. When the user clicks the "Add Row" button, the first row should be cloned and repeated...but the user can't add more than 5 rows. Later all the information need to be saved in a SQL table. How this can be achieved in C#?
I am attaching my sample ASP.NET. Can any one PLEASE help me?
PS: I have already read and tried "How to: Add Rows and Cells Dynamically to a Table Web Server Control"....but that's not working for me.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Testing Adding Rows</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="Table1" runat="server" width="400" style="border:[none][0]; border-color:White; border-style:hidden">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell runat="server" nowrap="nowrap" Width= "70">
<asp:Label ID="nameLabel" runat="server" Text="Your Name" Font-Size="X-Small"></asp:Label>
</asp:TableCell>
<asp:TableCell runat="server" nowrap="nowrap" Width= "100">
<asp:TextBox ID="tb_name" runat="server" Font-Size="Smaller"></asp:TextBox>
<asp:RequiredFieldValidator ID="nameValidator" runat="server" ControlToValidate="tb_name" Font-Size="Smaller">*</asp:RequiredFieldValidator>
</asp:TableCell>
<asp:TableCell runat="server" nowrap="nowrap" Width= "70">
<asp:Label ID="dateLabel" runat="server" Text="Birthdate" Font-Size="Smaller" ></asp:Label>
</asp:TableCell>
<asp:TableCell runat="server" Width= "100">
<asp:TextBox ID="tb_date" runat="server" Font-Size="Smaller"></asp:TextBox>
<asp:RequiredFieldValidator ID="dateValidator" runat="server" ControlToValidate="tb_date" Font-Size="Smaller">*</asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow2" runat="server">
<asp:TableCell runat="server" align="left" Width= "100">
<asp:Button ID="addRow" runat="server" Height="22px" Text="Add Row"
ToolTip="Click to add another row" onclick="ButtonAddRow_Click" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow3" runat="server">
<asp:TableCell runat="server" bordercolor="#FFFFFF"> </asp:TableCell>
<asp:TableCell runat="server" align="left" nowrap="nowrap" bordercolor="#FFFFFF">
<asp:Label ID="msg" runat="server" ForeColor="Red" Font-Size="Smaller"></asp:Label>
<asp:ValidationSummary ID="LogonValidationSummary" HeaderText="All the fields (*) are required." DisplayMode="SingleParagraph"
Font-Italic="true" ShowSummary="True" EnableClientScript="true" runat="server" Font-Size="Smaller"/>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow4" runat="server">
<asp:TableCell ID="TableCell10" runat="server" bordercolor="#FFFFFF"> </asp:TableCell>
<asp:TableCell ID="TableCell11" runat="server" align="left" bordercolor="#FFFFFF">
<asp:Button ID="ButtonSubmit" runat="server" Height="22px" Text="Submit" Width="79px" onclick="ButtonSubmit_Click" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
</html>
This codes snippet is just a hint that you can do this way..
TableRow row = new TableRow();
for (int j = 0; j < colsCount; j++)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox();
tb.ID = "TextBoxRow_" + i + "Col_" + j;
cell.Controls.Add(tb);
row.Cells.Add(cell);
}
Table1.Rows.Add(row);
I would like if you make use of GridView control and than add row runtime to gridview rather than using table. That would minize your effort also code.
here is code for you : Adding Dynamic Rows in GridView with TextBoxes
I have a data list control which is placed inside a content place holder.
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
<asp:ScriptManager ID="MainScriptManager" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="dlProdocut" runat="server" RepeatColumns="3" EditItemIndex="-1"
RepeatDirection="Horizontal" OnItemDataBound="dlProdocut_ItemDataBound">
<ItemTemplate>
<asp:Table ID="Table1" runat="server" border="0" CellSpacing="0" CellPadding="0">
<asp:TableRow>
<asp:TableCell Height="10" HorizontalAlign="Center" VerticalAlign="Top">
</asp:TableCell>
</asp:TableRow>
<%--Image--%>
<asp:TableRow>
<asp:TableCell Height="150" Width="7" HorizontalAlign="left" VerticalAlign="top">
<asp:HyperLink ID="hyrProductImg" runat="server">
<img alt='<%# DataBinder.Eval(Container.DataItem,"Title")%>' src="../images/<%# DataBinder.Eval(Container.DataItem,"SmallImage") %>" border="0" width="226" height="166" />
</asp:HyperLink>
</asp:TableCell>
<asp:TableCell Width="5"> </asp:TableCell>
</asp:TableRow>
<%--Title--%>
<asp:TableRow>
<asp:TableCell Height="45" Width="7" CssClass="product-name" HorizontalAlign="Center"
VerticalAlign="Top">
<strong> <%# DataBinder.Eval(Container.DataItem, "Title")%></strong>
</asp:TableCell>
</asp:TableRow>
<%--ShortDescription--%>
<asp:TableRow>
<asp:TableCell Width="7" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ShortDescription")%>'></asp:Label>
</asp:TableCell>
</asp:TableRow>
<%--Read More--%>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left">
<asp:HyperLink ID="lnkProductDetails" CssClass="read-more" runat="server">Read More →</asp:HyperLink>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Height="60" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dlProdocut" />
<asp:AsyncPostBackTrigger ControlID="btnNext" />
</Triggers>
</asp:UpdatePanel>
<asp:Label ID="lblPage" runat="server" Text="" />
<asp:Button ID="btnPrevious" runat="server" Text="<<" />
<asp:Button ID="btnNext" runat="server" Text=">>" OnClick="btnNext_Click" />
<asp:Panel ID="BottomPager_Panel" runat="server">
</asp:Panel>
</asp:Content>
On click of next button i am doing paging on the control and navigating to the next page.
On page load i am doing this
if (!IsPostBack)
{
pageCount = 1;
PageNo = 1;
startPage = 6 * (PageNo - 1) + 1;
lastPage = startPage + 5;
bindDataList();
}
This is my code for bindDataList
public void bindDataList()
{
string source = ConfigurationManager.ConnectionStrings["Cad-B"].ToString();
SqlConnection con = new SqlConnection(source);
SqlCommand cmd = new SqlCommand("sp_GetProductPagingByMenuId", con);
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.CommandText = "sp_GetProductPagingByMenuId";
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#startPage", startPage);
cmd.Parameters.Add("#lastPage", lastPage);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
dlProdocut.DataSource = dt;
dlProdocut.DataBind();
}
On click of next button i have written the following code
protected void btnNext_Click(object sender, EventArgs e)
{
dlProdocut.DataSource = null;
dlProdocut.DataBind();
pageCount++;
PageNo = pageCount;
startPage = 6 * (PageNo - 1) + 1;
lastPage = startPage + 5;
bindDataList();
}
Problem i am facing is that it every time shows me the same content that is loaded the first time on the page. When i debug the code i can see that the data list is loaded with the new records but it is not reflected on the page i tried removing caching but it dint help. The moment i removed the next button from the trigger section it is giving me the proper record but the complete page is getting post back which i dont want. This is the removed code
<asp:AsyncPostBackTrigger ControlID="btnNext" />
Please help i am stuck with this since long. I am new to this technology. Thanks in advance.
Try :
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DatalistId$btnNext" />
</Triggers>