some dynamic dropdownlists don't update -- autopostback = true - c#

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.

Related

Is it possible to refresh the whole page using an updateprogress?

I'm trying to implement a reinitialization button in my page which is linked to an UpdatePanel (AsyncPostBackTrigger). When i click on the button, it deals with an UpdateProgress.
The problem is that, because the reinitialization button is linked with an update panel, it cannot reinitialize what is outside of the UpdatePanel.
Is there a way to do some changes to the controls outside of the UpdatePanel without adding an UpdatePanel for the whole page ? In this case, i want to reinitialize the DropDownLists, the Textbox and the Repeater contained in the UpdatePanel.
How the page is rendered
ASPX code :
<body style="padding: 50px;">
<form id="form1" runat="server">
<asp:Label runat="server" ID="test"></asp:Label>
<asp:HiddenField runat="server" ID="AllDemandsTypeHfi"></asp:HiddenField>
<asp:ScriptManager runat="server" ID="ScriptManager"></asp:ScriptManager>
<asp:Panel runat="server" CssClass="panel-page-title">Création de demande</asp:Panel>
<asp:Panel runat="server" CssClass="panel-primary">
<asp:Panel runat="server" CssClass="panel-heading">Configuration de la recherche</asp:Panel>
<asp:Panel runat="server" CssClass="panel-body">
<asp:Table runat="server">
<asp:TableRow ID="BankRow">
<asp:TableCell>
<asp:Label runat="server">Banque : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="BankDdl" AutoPostBack="true" OnSelectedIndexChanged="BankDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Famille : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="FamilyDdl" AutoPostBack="true" OnSelectedIndexChanged="FamilyDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Motif : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="MotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="MotiveDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Sous-motif : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="SubmotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="SubmotiveDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Mots-clés : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="KeywordsTbx" data-target="#modalSuggestions" data-toggle="modal"></asp:TextBox>
<div id="keywordsTbxSuggestions"></div>
<asp:HiddenField runat="server" ID="KeywordsSearchHfi"></asp:HiddenField>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
<asp:Button runat="server" ID="ResearchBtn" Text="Rechercher" OnClick="ResearchBtn_Click" />
<asp:Button runat="server" ID="ReinitializeBtn" Text="Réinitialiser" OnClick="ReinitializeBtn_Click" />
</asp:Panel>
</asp:Panel>
<br />
<asp:UpdatePanel runat="server" ID="ResultsUpnl" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" CssClass="panel-primary">
<asp:Panel runat="server" CssClass="panel-heading">Résultat de la recherche </asp:Panel>
<asp:Panel runat="server" CssClass="panel-body">
<asp:Label runat="server" ID="ResultsLb" Text="Veuillez sélectionner les critères de recherche, puis cliquer sur Rechercher."></asp:Label>
<asp:Repeater runat="server" ID="ResultsRpt">
<HeaderTemplate>
<asp:Label runat="server" Text="<b>Type de demande</b>"></asp:Label>
<table>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel runat="server">
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%# Eval("Title") %>' Target="_blank"></asp:HyperLink>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ResearchBtn" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ReinitializeBtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UppDemandsResult" runat="server" DisplayAfter="0">
<ProgressTemplate>
<div style="text-align: center;">
<table style="width: 100%;">
<tr>
<td>
<Loader:LoaderComponent ID="UcLoadingProgess" runat="server" />
</td>
</tr>
</table>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
Code-behind :
private void HandleReinitialization()
{
this.ResultsLb.Text = DemandCreationConstants.ResearchDefaultText;
this.familyDdlSelectedValue = string.Empty;
this.motiveDdlSelectedValue = string.Empty;
this.submotiveDdlSelectedValue = string.Empty;
this.LoadFamilies(true);
this.LoadMotives(false);
this.LoadSubmotives(false);
this.ResultsRpt.DataSource = null;
this.ResultsRpt.DataBind();
this.KeywordsSearchHfi.Value = string.Empty;
this.KeywordsTbx.Text = string.Empty;
LogServiceInstance.Debug("L'utilisateur " + UserSession.UserLogOn + " a réinitialisé la recherche.");
}
HandleReinitialization is launched by the event ReinitializeBtn_Click.
If understand you correctly, you will need to create UpdatePanel2 and add whatever controls into it, then in the button Click() method of the first UpdatePanel1 invoke the Update() method.
UpdatePanel2.Update();
Update:
Make sure you set the UpdateMode of UpdatePanel2 to "Conditional"
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
// Your controls
</ContentTemplate>
</asp:UpdatePanel>

Storing reservation data and displaying

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

How to insert a DropDownList inside the GridView's first header

I have a GridView where I have some data and also another HTML table right above with the DropDownList to filter the GridView. The only issue is, because they are two separate tables, the column doesn't match up. To make up for that, inside the RowCreated method I added the following as an example:
protected void yourTasksGV_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView hGrid = (GridView)sender;
GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableHeaderCell tcCell = new TableHeaderCell();
tcCell.Text = #"<asp:DropDownList ID='ddlTaskName2' CssClass='chosen-select' DataSourceID='dsPopulateTaskName2' AutoPostBack='true' DataValueField='Task Name' runat='server' Width='100%' Font-Size='11px' AppendDataBoundItems='true' OnSelectedIndexChanged='ddlTaskName_onSelectIndexChanged'>
<asp:ListItem Text='All' Value='%'></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID='sPopulateTaskName2' runat='server' ConnectionString='<%$ ConnectionStrings:gvConnString %>' SelectCommand=\""SELECT [actionname] from [OnBase].[hsi].[action]\""></asp:SqlDataSource>";
tcCell.ColumnSpan = 1;
gvrRow.Cells.Add(tcCell);
TableHeaderCell tcCell2 = new TableHeaderCell();
tcCell2.Text = "TEST #2";
tcCell2.ColumnSpan = 1;
gvrRow.Cells.Add(tcCell2);
yourTasksGV.Controls[0].Controls.AddAt(0, gvrRow);
}
}
I don't see any DropDownList when the GridView is created.
My table that I am using for filtering is this:
<table class="taskGridView" runat="server">
<tr>
<td>
<asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateTaskName" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlService" CssClass="chosen-select" DataSourceID="dsPopulateService" AutoPostBack="true" DataValueField="Service" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlService_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateService" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlStatus" CssClass="chosen-select" DataSourceID="dsPopulateStatus" AutoPostBack="true" DataValueField="Status" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlStatus_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateStatus" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlDueDate" CssClass="chosen-select" DataSourceID="dsPopulateDueDate" AutoPostBack="true" DataValueField="Due Date" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlDueDate_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateDueDate" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlOwner" CssClass="chosen-select" DataSourceID="dsPopulateOwner" AutoPostBack="true" DataValueField="Owner" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlOwner_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateOwner" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlClient" CssClass="chosen-select" DataSourceID="dsPopulateClient" AutoPostBack="true" DataValueField="Client" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlClient_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateClient" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlSite" CssClass="chosen-select" DataSourceID="dsPopulateSite" AutoPostBack="true" DataValueField="Site" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlSite_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateSite" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlPractice" CssClass="chosen-select" DataSourceID="dsPopulatePractice" AutoPostBack="true" DataValueField="Practice" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlPractice_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulatePractice" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="ddlProvider" CssClass="chosen-select" DataSourceID="dsPopulateProvider" AutoPostBack="true" DataValueField="Provider" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlProvider_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateProvider" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand=""></asp:SqlDataSource>
</td>
</tr>
</table>
I am populating the SelectCommand from code-behind on Page_Load. I am also calling another function on Page_Load which references the DropDownList but I get a The name 'DropDownList ID' does not exist in current content
My GridView:
<asp:GridView ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="You currently have no tasks assigned to you" OnRowDataBound="yourTasksGV_RowDataBound" OnRowCreated="yourTasksGV_RowCreated">
<Columns>
<asp:HyperLinkField Target="_self" DataNavigateUrlFields="Task Detail" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Detail" SortExpression="Task Name" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Service" HeaderText="Service" SortExpression="Service" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Due Date" HeaderText="Due" SortExpression="Due Date" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Site" HeaderText="Site" SortExpression="Site" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Practice" HeaderText="Practice" SortExpression="Practice" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField DataField="Provider" HeaderText="Provider" SortExpression="Provider" ItemStyle-CssClass="taskTableColumn" />
</Columns>
</asp:GridView>
What I want to do is take the DropDownList table and insert it inside the GridView HEADER right above the Header that is being generated.
As you can see in the below image the empty header where the DropDownList is supposed to go is there but I don't see anything. That's where I would like to put the DropDownList with the all option.
Rather than adding markup to the cell text, which won't be evaluated correctly in the page lifecycle in the same way as if you had declared it in the aspx source, add controls to the Controls collection of an existing control.
For example,
DropDownList ddlTaskName2 = new DropDownList();
tcCell.Controls.Add(ddlTaskName2);
This should enable you to solve the problem of the dropdown not appearing as you have shown like this:
Below is a minimal working example you can use, that adds a dropdown to a GridView header cell.
Markup:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewHeaderControl.aspx.cs"
Inherits="WebApplication7_JQuery.GridViewHeaderControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="gvMain" OnRowCreated="gvMain_RowCreated" />
</div>
</form>
</body>
</html>
Code-behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvMain.DataSource = new List<object> { new { ID = 1, Name = "First" }, new { ID = 2, Name = "Second" } };
gvMain.DataBind();
}
}
protected void gvMain_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView hGrid = (GridView)sender;
GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
DropDownList ddl = new DropDownList();
ddl.Items.Add("Option 1");
TableHeaderCell tcCell = new TableHeaderCell();
tcCell.Controls.Add(ddl);
gvrRow.Cells.Add(tcCell);
gvMain.Controls[0].Controls.AddAt(0, gvrRow);
}
}
Set further properties of the dropdown as desired, per the markup that was loaded as cell text in your question.
You may need to explicitly code ddl.DataBind() after setting your datasourceid, depending on when you do other binding.
Here the ddl is dynamically created; however, you may wish to declare it in your markup instead so it gets a design-time variable you can reference anywhere in your code-behind for binding and other purposes:
<asp:GridView runat="server" ID="gvMain" OnRowCreated="gvMain_RowCreated" />
<asp:DropDownList runat="server" ID="ddlTaskName" />
and
tcCell.Controls.Add(ddlTaskName);

Add rows of textboxes with a click of a button

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

ajax with datalist giving error

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>

Categories

Resources