Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > 'dropdownlist' has a selectedvalue which is invalid because it does not exist in the list of items.p

Reply
Thread Tools

'dropdownlist' has a selectedvalue which is invalid because it does not exist in the list of items.p

 
 
sree reddy
Guest
Posts: n/a
 
      06-22-2007

..cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;

public partial class CompanyDepartments : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

((LinkButton)CompanyTabs.FindControl("LinkButton4" )).CssClass =
"tabselected";
((TableCell)CompanyTabs.FindControl("TableCell10") ).CssClass
= "tabselectedl";
((TableCell)CompanyTabs.FindControl("TableCell11") ).CssClass
= "tabselected";
((TableCell)CompanyTabs.FindControl("TableCell12") ).CssClass
= "tabselectedr";

this.BindDPGridView();

ddlSelectCompany.DataSource =
PMPro.BusinessClasses.HRCompany.SelectAllHRCompany ByDescription_DataRead
er();
ddlSelectCompany.DataBind();
ddlSelectCompany.Items.Insert(0, new ListItem("--", ""));

ddlSelectDivision.DataSource =
PMPro.BusinessClasses.HRDivisions.SelectAllHRDivis ionsByDescription_Data
Reader();
ddlSelectDivision.DataBind();
ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));

ddlSelectLocation.DataSource =
PMPro.BusinessClasses.HRLocations.SelectAllHRLocat ionByDescription_DataR
eader();
ddlSelectLocation.DataBind();
ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));


}
}
protected override void Render(HtmlTextWriter writer)
{
if (DPGridView.Rows.Count > 0)
{
foreach (GridViewRow row in DPGridView.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
row.Attributes.Add("onclick",
Page.ClientScript.GetPostBackEventReference(DPGrid View, "Select$" +
row.RowIndex.ToString(), true));
}
}
}

base.Render(writer);
}

protected void lnkConfirmY1_Click(object sender, EventArgs e)
{
divConfirm.Visible = false;
}


protected void lnkErrorY1_Click(object sender, EventArgs e)
{
divConfirm.Visible = false;
}


private void ClearControls()
{
txtDepartmentName.Text = "";
txtDepartmentCode.Text = "";
ddlSelectCompany.ClearSelection();
ddlSelectDivision.ClearSelection();
}

private void BindDPGridView()
{
//if (Request.QueryString["HDepartmentId"] != null &&
Request.QueryString["HDepartmentId"].ToString() != "")
//{
DPGridView.DataSource =
PMPro.BusinessClasses.HRDepartments.SelectAllHRDep artmentsTypesByHRDepar
tmentsTypeId_DataTable();
DPGridView.DataBind();
DPGridView.SelectedIndex = 0;
//}
}
protected void DPGridView_OnDataBound(object sender, EventArgs e)
{
if (DPGridView.Rows.Count > 0)
{
DPEdit.Visible = true;
DPDelete.Visible = true;
}
else
{
DPEdit.Visible = false;
DPDelete.Visible = false;
}
}

protected void DPAddNew_Click(object sender, EventArgs e)
{
this.ClearControls();
divDepartmentsInfo.Visible = true;
DPInsert.Visible = true;
DPUpdate.Visible = false;
}
protected void DPEdit_Click(object sender, EventArgs e)
{
if (DPGridView.SelectedValue != null)
{
this.FillDPControls();
divDepartmentsInfo.Visible = true;
DPInsert.Visible = false;
DPUpdate.Visible = true;

}

}
protected void DPDelete_Click(object sender, EventArgs e)
{
if (DPGridView.SelectedValue != null)
{
delConfirm.Visible = true;
DPYes.Visible = true;
lblConfirmDel.Text =
string.Format(Resources.Resource.MSG_ITEM_DELETE_C ONFIRMATION," "+
"Company / Locations Department : " +
DPGridView.DataKeys[DPGridView.SelectedIndex].Values["DepartmentName"].T
oString() + "</b>");
}
}
private void DPConfirmationActions(string ErrorMessage, LinkButton
VisibleLink, bool IsSuccess)
{
divConfirm.Visible = true;
lnkConfirmY1.Visible = false;
lnkErrorY1.Visible = false;
VisibleLink.Visible = true;
if (IsSuccess)
{
ImgConfirm.ImageUrl =
"~/App_Themes/Blue/Images/correct.gif";
}
else
{
ImgConfirm.ImageUrl = "~/App_Themes/Blue/Images/error.gif";
}
lblConfirm.Text = ErrorMessage;
}

protected void DPInsert_Click(object sender, EventArgs e)
{

object HCompanyId = null; if
(ddlSelectCompany.SelectedValue.Length > 0) { HCompanyId =
Int32.Parse(ddlSelectCompany.SelectedValue); }
object HLocationId = null; if
(ddlSelectLocation.SelectedValue.Length > 0) { HLocationId =
Int32.Parse(ddlSelectLocation.SelectedValue); }
object HDivisionId = null; if
(ddlSelectDivision.SelectedValue.Length > 0) { HDivisionId =
Int32.Parse(ddlSelectDivision.SelectedValue); }
object DepartmentName = null; if
(txtDepartmentName.Text.Trim().Length > 0) { DepartmentName =
txtDepartmentName.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentCode.Text.Trim().Length > 0) { DepartmentCode =
txtDepartmentCode.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessClasses.HRDepartments.Insert(HCompan yId, HLocationId,
HDivisionId, txtDepartmentName.Text.Trim(),
txtDepartmentCode.Text.Trim());

divConfirm.Visible = true;


if (RecordStatus == 1)
{

this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_ADD
, "DepartmentName"), lnkConfirmY1, true);
divDepartmentsInfo.Visible = false;
this.ClearControls();
this.BindDPGridView();

}
if (RecordStatus == 0)
{
lblConfirm.Text =
string.Format(Resources.Resource.MSG_ITEM_ALREADY_ EXISTS, "Information",
"Name");

}
}

protected void DPUpdate_Click(object sender, EventArgs e)
{

object DepartmentName = null; if
(txtDepartmentName.Text.Trim().Length > 0) { DepartmentName =
txtDepartmentName.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentCode.Text.Trim().Length > 0) { DepartmentCode =
txtDepartmentCode.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessClasses.HRDepartments.Update((Int32) DPGridView.SelectedVal
ue, Int32.Parse(ddlSelectCompany.SelectedValue),
Int32.Parse(ddlSelectLocation.SelectedValue),
Int32.Parse(ddlSelectDivision.SelectedValue),
txtDepartmentName.Text.Trim(), txtDepartmentCode.Text.Trim());

divConfirm.Visible = true;


if (RecordStatus == 1)
{

this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_UPD
ATE, "Department"), lnkConfirmY1, true);
divDepartmentsInfo.Visible = false;
this.ClearControls();
this.BindDPGridView();
}
else
{

this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_ALR
EADY_EXISTS1, txtDepartmentName.Text + "Department Information"),
lnkErrorY1, false);
}
}
protected void DPYes_Click(object sender, EventArgs e)
{

PMPro.BusinessClasses.HRDepartments.Delete((Int32) (DPGridView.SelectedVa
lue));

divDepartmentsInfo.Visible = false;
delConfirm.Visible = false;


this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_DEL
ETE, "DepartmentTypes"), lnkConfirmY1, true);

this.BindDPGridView();
}
protected void No_Click(object sender, EventArgs e)
{
delConfirm.Visible = false;
}
protected void lnkAClose_Click(object sender, EventArgs e)
{
divDepartmentsInfo.Visible = false;
}
protected void DPCancel_Click(object sender, EventArgs e)
{
divDepartmentsInfo.Visible = false;
}

private void FillDPControls()
{
if (DPGridView.SelectedValue != null)
{
int Index = DPGridView.SelectedIndex;

ddlSelectCompany.SelectedValue =
DPGridView.DataKeys[Index].Values["HCompanyId"].ToString();

ddlSelectLocation.SelectedValue =
DPGridView.DataKeys[Index].Values["HLocationId"].ToString();
ddlSelectDivision.SelectedValue=
DPGridView.DataKeys[Index].Values["HDivisionId"].ToString();
txtDepartmentName.Text=
DPGridView.DataKeys[Index].Values["DepartmentName"].ToString();
txtDepartmentCode.Text=
DPGridView.DataKeys[Index].Values["DepartmentCode"].ToString();

}

}
protected void ddlSelectCompany_SelectedIndexChanged(object sender,
EventArgs e)
{

ddlSelectLocation.Items.Clear();
ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));

if (ddlSelectCompany.SelectedValue != "")
{
ddlSelectLocation.DataSource =
PMPro.BusinessClasses.HRPersonLocations.SelectAllP ersonAccessibleLocatio
nsByPersonId_DataReader(Int32.Parse(ddlSelectCompa ny.SelectedValue));
ddlSelectLocation.DataBind();
ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));

}
}
protected void ddlSelectLocation_SelectedIndexChanged(object sender,
EventArgs e)
{

ddlSelectDivision.Items.Clear();
ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));

if (ddlSelectLocation.SelectedValue != "")
{
ddlSelectDivision.DataSource =
PMPro.BusinessClasses.HRDivisions.SelectAllPersonA ccessibleDivisionsByPe
rsonId_DataReader(Int32.Parse(ddlSelectLocation.Se lectedValue));
ddlSelectDivision.DataBind();
ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));

}
}
}


..aspx

<%@ Page Language="C#" MasterPageFile="~/Master/Sub.master"
AutoEventWireup="true" CodeFile="CompanyDepartments.aspx.cs"
Inherits="CompanyDepartments" Theme="Blue" %>
<%@ Register TagPrefix="uc" TagName=CompanyTabs
Src="~/Controls/CompanyTabs.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CPH1" Runat="Server">
<div id="divWrapC" class="divWrapperC"></div>
<asp:UpdatePanel ID="GVPanel" runat="server">
<ContentTemplate>
<DIV id="divConfirm" class="divConfirm" runat="server"
visible="false">
<table class="tableContent" cellSpacing=0 cellPadding=0
width="500px">
<tr class="trContent">
<td align=left colspan="2"
style="padding-left:5px;">Confirmation</td>
</tr>
<tr style="height:85px;">
<td style="width:25%;" align="center"
valign="middle"><asp:Image id="ImgConfirm" runat="server" /></td>
<td align="left" valign="middle"
style="padding-right:5px;" >
<asp:Label id="lblConfirm"
runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="center" valign="top" colspan="2">
<asp:LinkButton CausesValidation="false"
id="lnkConfirmY1" onclick="lnkConfirmY1_Click" runat="server" Text="OK"
CssClass="but_sub"
OnClientClick="hideWrap('divWrap');hideWrap('divWr apC');" Height="18"
Width="60"></asp:LinkButton>
<asp:LinkButton CausesValidation="false"
id="lnkErrorY1" onclick="lnkErrorY1_Click" runat="server" Text="OK"
CssClass="but_sub" OnClientClick="hideWrap('divWrapC');" Height="18"
Width="60"></asp:LinkButton>
</td>
</tr>
</table>
</div>
<DIV id="delConfirm" class="divContent" runat="server"
visible="false">
<table class="tableContent" cellSpacing=0 cellPadding=0>
<TR class="trContent">
<td align=left style="padding-left:5px;"></td>
</tr>
<tr>
<td>
<DIV style="OVERFLOW: auto; WIDTH:500px;
HEIGHT:120px;">
<table width="100%" >
<tr height="85px">
<td align="center">
<asp:Label
id="lblConfirmDel" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:LinkButton id="DPYes"
runat="server" Text="Yes" CssClass="but_sub" Height="18" Width="60"
OnClientClick="showWrap('divWrapC', false);"
onClick="DPYes_Click"></asp:LinkButton>
&nbsp;<asp:LinkButton
id="No" onClick="No_Click" runat="server" Text="No" CssClass="but_sub"
OnClientClick="hideWrap('divWrap');" Height="18"
Width="60"></asp:LinkButton>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
<table width="100%" border="0" cellspacing="0"
cellpadding="0" style="padding-left: 10px; padding-right: 10px;">
<tr>
<td>
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td style="height:18px;" valign="bottom"
class="textheading">Company Setup</td>
</tr>
<tr>
<td style="height:1px;"
class="dotline"></td>
</tr>
<tr>
<td style="height:10px;"
align="right"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<uc:CompanyTabs ID="CompanyTabs" runat="server"
/>
</td>
</tr>
</table>
<table id="tableDepartments" runat="server" width="100%"
border="0" cellspacing="0" cellpadding="0" style="padding-left: 10px;
padding-right: 10px;">
<tr>
<td>
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td style="height:5px;"></td>
</tr>
<tr>
<td class="textsubheading">Departments
Info</td>
<td align="right"><asp:LinkButton
ID="DPAddNew" runat="server" Text="Add New" CssClass="but_sub"
Height="18" Width="60" OnClientClick="showWrap('divWrap', false);"
OnClick="DPAddNew_Click"></asp:LinkButton>&nbsp;<asp:LinkButton
ID="DPEdit" runat="server" Text="Edit" CssClass="but_sub" Height="18"
Width="60" OnClientClick="showWrap('divWrap',true);"
OnClick="DPEdit_Click"></asp:LinkButton>&nbsp;<asp:LinkButton
ID="DPDelete" runat="server" Text="Delete" CssClass="but_sub"
Height="18" Width="60" OnClientClick="showWrap('divWrap',true);"
onClick="DPDelete_Click"></asp:LinkButton></td>
</tr>
<tr>
<td colspan="2">
<asp:GridView SkinID="List"
ID="DPGridView" runat="server"
DataKeyNames="HDepartmentId,HLocationId,HCompanyId ,HDivisionId,Departmen
tName,DepartmentCode,LocationName" OnDataBound="DPGridView_OnDataBound">

<Columns>
<asp:BoundField
HeaderText="Company" DataField="CompanyName" ItemStyle-Width="19%" />
<asp:BoundField
HeaderText="LocationName" DataField="LocationName" ItemStyle-Width="19%"
/>
<asp:BoundField
HeaderText="DivisionName" DataField="DivisionName" ItemStyle-Width="19%"
/>
<asp:BoundField
HeaderText="DepartmentName" DataField="DepartmentName"
ItemStyle-Width="24%" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="height:5px;"></td>
</tr>
</table>
<div id="divDepartmentsInfo" runat="server"
class="divContent" visible="false">
<table class="tableContent" cellSpacing=0 cellPadding=0>
<tr class="trContent">
<td align=left
style="padding-left:5px;">Add/Edit Departments Info</td>
<td align=right>
<asp:LinkButton id="lnkAClose"
onclick="lnkAClose_Click" runat="server" Text="X" CssClass=""
CausesValidation="False" OnClientClick="hideWrap('divWrap');"
ToolTip="Close"></asp:LinkButton>&nbsp;
</td>
</tr>
<tr>
<td style="height:5px;"></td>
</tr>
<tr>
<td colspan=2>
<div style="OVERFLOW: auto; WIDTH: 700px;
HEIGHT: 300px";>
<table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"
style="height:9px; padding-left:3px;"><asp:ValidationSummary
ValidationGroup="Departments" ID="vsDepartments" runat="server"
HeaderText="Invalid Values: " DisplayMode="SingleParagraph" /></td>
</tr>
<tr>
<td style="height:15px;"></td>
</tr>
<tr>
<td style="height:22px;"
align="right">Select Company:&nbsp;</td>
<td><aspropDownList
id="ddlSelectCompany" runat="server" CssClass="textboxmust"
Width="115px" DataTextField="CompanyName" DataValueField="HCompanyId"
TabIndex="1" AutoPostBack=true
OnSelectedIndexChanged="ddlSelectCompany_SelectedI ndexChanged"
AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
or ID="rfvSelectCompany" runat="Server" ValidationGroup="Departments"
ControlToValidate="ddlSelectCompany" ErrorMessage="Company;"
ToolTip="Select Company.">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="height:22px;"
align=right>Select Location:&nbsp;</td>
<td><aspropDownList
id="ddlSelectLocation" runat="server" CssClass="textboxmust"
Width="115px" DataTextField="LocationName" DataValueField="HLocationId"
TabIndex="2" AutoPostBack=true
OnSelectedIndexChanged="ddlSelectLocation_Selected IndexChanged"
AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
or ID="rfvSelectLocation" runat="Server" ValidationGroup="Departments"
ControlToValidate="ddlSelectLocation" ErrorMessage="Location;"
ToolTip="Select Location."
SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="height:22px;"
align=right>Select Division:&nbsp;</td>
<td><aspropDownList
id="ddlSelectDivision" runat="server" CssClass="textboxmust"
Width="115px" DataTextField="DivisionName" DataValueField="HDivisionId"
TabIndex="2" AutoPostBack=true
AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
or ID="rfvSelectDivision" runat="Server" ValidationGroup="Departments"
ControlToValidate="ddlSelectDivision" ErrorMessage="Division;"
ToolTip="Select Division."
SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="height:22px;"
align="right">Department Name:&nbsp;</td>
<td><asp:TextBox
ID="txtDepartmentName" runat="server" CssClass="textboxmust"
TabIndex="3"></asp:TextBox><asp:RequiredFieldValidator
ID="rfvtxtDepartmentName" runat="Server" ValidationGroup="Departments"
ControlToValidate="txtDepartmentName" ErrorMessage="Department;"
ToolTip="Enter Department."
SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
</tr>

<tr>
<td style="height:22px;"
align="right">Code #:&nbsp;</td>
<td><asp:TextBox
ID="txtDepartmentCode" runat="server" CssClass="textboxmust"
TabIndex="5"></asp:TextBox><asp:RequiredFieldValidator
ID="rfvDepartmentCode" runat="server" ValidationGroup="Departments"
ControlToValidate="txtDepartmentCode" ErrorMessage="Code;"
ToolTip="Enter Department Code."
SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="height:15px;"></td>
</tr>
<tr>
<td colspan=1 ></td>
<td
style="height:22px;"><asp:LinkButton ValidationGroup="Departments"
ID="DPInsert" runat="server" Text="Insert" CssClass="but_sub"
Height="18" Width="60" OnClientClick="showWrap('divWrapC',true);"
onClick="DPInsert_Click" TabIndex="9"></asp:LinkButton><asp:LinkButton
ValidationGroup="Departments" ID="DPUpdate" runat="server" Text="Update"
CssClass="but_sub" Height="18" Width="60"
OnClientClick="showWrap('divWrapC',true);" onClick="DPUpdate_Click"
TabIndex="9"></asp:LinkButton>&nbsp;<asp:LinkButton
CausesValidation="false" ID="DPCancel" runat="server" Text="Cancel"
CssClass="but_sub" Height="18" Width="60"
OnClientClick="hideWrap('divWrap');" OnClick="DPCancel_Click"
TabIndex="10"></asp:LinkButton></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>

</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>




*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-22-2007
On Jun 22, 8:33 am, sree reddy <(E-Mail Removed)> wrote:
> .cs
>
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
> using System.Data.Sql;
> using System.Data.SqlClient;
>
> public partial class CompanyDepartments : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> if (!IsPostBack)
> {
>
> ((LinkButton)CompanyTabs.FindControl("LinkButton4" )).CssClass =
> "tabselected";
> ((TableCell)CompanyTabs.FindControl("TableCell10") ).CssClass
> = "tabselectedl";
> ((TableCell)CompanyTabs.FindControl("TableCell11") ).CssClass
> = "tabselected";
> ((TableCell)CompanyTabs.FindControl("TableCell12") ).CssClass
> = "tabselectedr";
>
> this.BindDPGridView();
>
> ddlSelectCompany.DataSource =
> PMPro.BusinessClasses.HRCompany.SelectAllHRCompany ByDescription_DataRead
> er();
> ddlSelectCompany.DataBind();
> ddlSelectCompany.Items.Insert(0, new ListItem("--", ""));
>
> ddlSelectDivision.DataSource =
> PMPro.BusinessClasses.HRDivisions.SelectAllHRDivis ionsByDescription_Data
> Reader();
> ddlSelectDivision.DataBind();
> ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
>
> ddlSelectLocation.DataSource =
> PMPro.BusinessClasses.HRLocations.SelectAllHRLocat ionByDescription_DataR
> eader();
> ddlSelectLocation.DataBind();
> ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));
>
> }
> }
> protected override void Render(HtmlTextWriter writer)
> {
> if (DPGridView.Rows.Count > 0)
> {
> foreach (GridViewRow row in DPGridView.Rows)
> {
> if (row.RowType == DataControlRowType.DataRow)
> {
> row.Attributes.Add("onclick",
> Page.ClientScript.GetPostBackEventReference(DPGrid View, "Select$" +
> row.RowIndex.ToString(), true));
> }
> }
> }
>
> base.Render(writer);
> }
>
> protected void lnkConfirmY1_Click(object sender, EventArgs e)
> {
> divConfirm.Visible = false;
> }
>
> protected void lnkErrorY1_Click(object sender, EventArgs e)
> {
> divConfirm.Visible = false;
> }
>
> private void ClearControls()
> {
> txtDepartmentName.Text = "";
> txtDepartmentCode.Text = "";
> ddlSelectCompany.ClearSelection();
> ddlSelectDivision.ClearSelection();
> }
>
> private void BindDPGridView()
> {
> //if (Request.QueryString["HDepartmentId"] != null &&
> Request.QueryString["HDepartmentId"].ToString() != "")
> //{
> DPGridView.DataSource =
> PMPro.BusinessClasses.HRDepartments.SelectAllHRDep artmentsTypesByHRDepar
> tmentsTypeId_DataTable();
> DPGridView.DataBind();
> DPGridView.SelectedIndex = 0;
> //}
> }
> protected void DPGridView_OnDataBound(object sender, EventArgs e)
> {
> if (DPGridView.Rows.Count > 0)
> {
> DPEdit.Visible = true;
> DPDelete.Visible = true;
> }
> else
> {
> DPEdit.Visible = false;
> DPDelete.Visible = false;
> }
> }
>
> protected void DPAddNew_Click(object sender, EventArgs e)
> {
> this.ClearControls();
> divDepartmentsInfo.Visible = true;
> DPInsert.Visible = true;
> DPUpdate.Visible = false;
> }
> protected void DPEdit_Click(object sender, EventArgs e)
> {
> if (DPGridView.SelectedValue != null)
> {
> this.FillDPControls();
> divDepartmentsInfo.Visible = true;
> DPInsert.Visible = false;
> DPUpdate.Visible = true;
>
> }
>
> }
> protected void DPDelete_Click(object sender, EventArgs e)
> {
> if (DPGridView.SelectedValue != null)
> {
> delConfirm.Visible = true;
> DPYes.Visible = true;
> lblConfirmDel.Text =
> string.Format(Resources.Resource.MSG_ITEM_DELETE_C ONFIRMATION," "+
> "Company / Locations Department : " +
> DPGridView.DataKeys[DPGridView.SelectedIndex].Values["DepartmentName"].T
> oString() + "</b>");
> }
> }
> private void DPConfirmationActions(string ErrorMessage, LinkButton
> VisibleLink, bool IsSuccess)
> {
> divConfirm.Visible = true;
> lnkConfirmY1.Visible = false;
> lnkErrorY1.Visible = false;
> VisibleLink.Visible = true;
> if (IsSuccess)
> {
> ImgConfirm.ImageUrl =
> "~/App_Themes/Blue/Images/correct.gif";
> }
> else
> {
> ImgConfirm.ImageUrl = "~/App_Themes/Blue/Images/error.gif";
> }
> lblConfirm.Text = ErrorMessage;
> }
>
> protected void DPInsert_Click(object sender, EventArgs e)
> {
>
> object HCompanyId = null; if
> (ddlSelectCompany.SelectedValue.Length > 0) { HCompanyId =
> Int32.Parse(ddlSelectCompany.SelectedValue); }
> object HLocationId = null; if
> (ddlSelectLocation.SelectedValue.Length > 0) { HLocationId =
> Int32.Parse(ddlSelectLocation.SelectedValue); }
> object HDivisionId = null; if
> (ddlSelectDivision.SelectedValue.Length > 0) { HDivisionId =
> Int32.Parse(ddlSelectDivision.SelectedValue); }
> object DepartmentName = null; if
> (txtDepartmentName.Text.Trim().Length > 0) { DepartmentName =
> txtDepartmentName.Text.Trim(); }
> object DepartmentCode = null; if
> (txtDepartmentCode.Text.Trim().Length > 0) { DepartmentCode =
> txtDepartmentCode.Text.Trim(); }
> Int16 RecordStatus =
> PMPro.BusinessClasses.HRDepartments.Insert(HCompan yId, HLocationId,
> HDivisionId, txtDepartmentName.Text.Trim(),
> txtDepartmentCode.Text.Trim());
>
> divConfirm.Visible = true;
>
> if (RecordStatus == 1)
> {
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_ADD
> , "DepartmentName"), lnkConfirmY1, true);
> divDepartmentsInfo.Visible = false;
> this.ClearControls();
> this.BindDPGridView();
>
> }
> if (RecordStatus == 0)
> {
> lblConfirm.Text =
> string.Format(Resources.Resource.MSG_ITEM_ALREADY_ EXISTS, "Information",
> "Name");
>
> }
> }
>
> protected void DPUpdate_Click(object sender, EventArgs e)
> {
>
> object DepartmentName = null; if
> (txtDepartmentName.Text.Trim().Length > 0) { DepartmentName =
> txtDepartmentName.Text.Trim(); }
> object DepartmentCode = null; if
> (txtDepartmentCode.Text.Trim().Length > 0) { DepartmentCode =
> txtDepartmentCode.Text.Trim(); }
> Int16 RecordStatus =
> PMPro.BusinessClasses.HRDepartments.Update((Int32) DPGridView.SelectedVal
> ue, Int32.Parse(ddlSelectCompany.SelectedValue),
> Int32.Parse(ddlSelectLocation.SelectedValue),
> Int32.Parse(ddlSelectDivision.SelectedValue),
> txtDepartmentName.Text.Trim(), txtDepartmentCode.Text.Trim());
>
> divConfirm.Visible = true;
>
> if (RecordStatus == 1)
> {
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_UPD
> ATE, "Department"), lnkConfirmY1, true);
> divDepartmentsInfo.Visible = false;
> this.ClearControls();
> this.BindDPGridView();
> }
> else
> {
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_ALR
> EADY_EXISTS1, txtDepartmentName.Text + "Department Information"),
> lnkErrorY1, false);
> }
> }
> protected void DPYes_Click(object sender, EventArgs e)
> {
>
> PMPro.BusinessClasses.HRDepartments.Delete((Int32) (DPGridView.SelectedVa
> lue));
>
> divDepartmentsInfo.Visible = false;
> delConfirm.Visible = false;
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_DEL
> ETE, "DepartmentTypes"), lnkConfirmY1, true);
>
> this.BindDPGridView();
> }
> protected void No_Click(object sender, EventArgs e)
> {
> delConfirm.Visible = false;
> }
> protected void lnkAClose_Click(object sender, EventArgs e)
> {
> divDepartmentsInfo.Visible = false;
> }
> protected void DPCancel_Click(object sender, EventArgs e)
> {
> divDepartmentsInfo.Visible = false;
> }
>
> private void FillDPControls()
> {
> if (DPGridView.SelectedValue != null)
> {
> int Index = DPGridView.SelectedIndex;
>
> ddlSelectCompany.SelectedValue =
> DPGridView.DataKeys[Index].Values["HCompanyId"].ToString();
>
> ddlSelectLocation.SelectedValue =
> DPGridView.DataKeys[Index].Values["HLocationId"].ToString();
> ddlSelectDivision.SelectedValue=
> DPGridView.DataKeys[Index].Values["HDivisionId"].ToString();
> txtDepartmentName.Text=
> DPGridView.DataKeys[Index].Values["DepartmentName"].ToString();
> txtDepartmentCode.Text=
> DPGridView.DataKeys[Index].Values["DepartmentCode"].ToString();
>
> }
>
> }
> protected void ddlSelectCompany_SelectedIndexChanged(object sender,
> EventArgs e)
> {
>
> ddlSelectLocation.Items.Clear();
> ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));
>
> if (ddlSelectCompany.SelectedValue != "")
> {
> ddlSelectLocation.DataSource =
> PMPro.BusinessClasses.HRPersonLocations.SelectAllP ersonAccessibleLocatio
> nsByPersonId_DataReader(Int32.Parse(ddlSelectCompa ny.SelectedValue));
> ddlSelectLocation.DataBind();
> ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));
>
> }
> }
> protected void ddlSelectLocation_SelectedIndexChanged(object sender,
> EventArgs e)
> {
>
> ddlSelectDivision.Items.Clear();
> ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
>
> if (ddlSelectLocation.SelectedValue != "")
> {
> ddlSelectDivision.DataSource =
> PMPro.BusinessClasses.HRDivisions.SelectAllPersonA ccessibleDivisionsByPe
> rsonId_DataReader(Int32.Parse(ddlSelectLocation.Se lectedValue));
> ddlSelectDivision.DataBind();
> ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
>
> }
> }
>
> }
>
> .aspx
>
> <%@ Page Language="C#" MasterPageFile="~/Master/Sub.master"
> AutoEventWireup="true" CodeFile="CompanyDepartments.aspx.cs"
> Inherits="CompanyDepartments" Theme="Blue" %>
> <%@ Register TagPrefix="uc" TagName=CompanyTabs
> Src="~/Controls/CompanyTabs.ascx" %>
> <asp:Content ID="Content1" ContentPlaceHolderID="CPH1" Runat="Server">
> <div id="divWrapC" class="divWrapperC"></div>
> <asp:UpdatePanel ID="GVPanel" runat="server">
> <ContentTemplate>
> <DIV id="divConfirm" class="divConfirm" runat="server"
> visible="false">
> <table class="tableContent" cellSpacing=0 cellPadding=0
> width="500px">
> <tr class="trContent">
> <td align=left colspan="2"
> style="padding-left:5px;">Confirmation</td>
> </tr>
> <tr style="height:85px;">
> <td style="width:25%;" align="center"
> valign="middle"><asp:Image id="ImgConfirm" runat="server" /></td>
> <td align="left" valign="middle"
> style="padding-right:5px;" >
> <asp:Label id="lblConfirm"
> runat="server"></asp:Label>
> </td>
> </tr>
> <tr>
> <td align="center" valign="top" colspan="2">
> <asp:LinkButton CausesValidation="false"
> id="lnkConfirmY1" onclick="lnkConfirmY1_Click" runat="server" Text="OK"
> CssClass="but_sub"
> OnClientClick="hideWrap('divWrap');hideWrap('divWr apC');" Height="18"
> Width="60"></asp:LinkButton>
> <asp:LinkButton CausesValidation="false"
> id="lnkErrorY1" onclick="lnkErrorY1_Click" runat="server" Text="OK"
> CssClass="but_sub" OnClientClick="hideWrap('divWrapC');" Height="18"
> Width="60"></asp:LinkButton>
> </td>
> </tr>
> </table>
> </div>
> <DIV id="delConfirm" class="divContent" runat="server"
> visible="false">
> <table class="tableContent" cellSpacing=0 cellPadding=0>
> <TR class="trContent">
> <td align=left style="padding-left:5px;"></td>
> </tr>
> <tr>
> <td>
> <DIV style="OVERFLOW: auto; WIDTH:500px;
> HEIGHT:120px;">
> <table width="100%" >
> <tr height="85px">
> <td align="center">
> <asp:Label
> id="lblConfirmDel" runat="server"></asp:Label>
> </td>
> </tr>
> <tr>
> <td align="center">
> <asp:LinkButton id="DPYes"
> runat="server" Text="Yes" CssClass="but_sub" Height="18" Width="60"
> OnClientClick="showWrap('divWrapC', false);"
> onClick="DPYes_Click"></asp:LinkButton>
> &nbsp;<asp:LinkButton
> id="No" onClick="No_Click" runat="server" Text="No" CssClass="but_sub"
> OnClientClick="hideWrap('divWrap');" Height="18"
> Width="60"></asp:LinkButton>
> </td>
> </tr>
> </table>
> </div>
> </td>
> </tr>
> </table>
> </div>
> <table width="100%" border="0" cellspacing="0"
> cellpadding="0" style="padding-left: 10px; padding-right: 10px;">
> <tr>
> <td>
> <table width="100%" border="0" cellspacing="0"
> cellpadding="0">
> <tr>
> <td style="height:18px;" valign="bottom"
> class="textheading">Company Setup</td>
> </tr>
> <tr>
> <td style="height:1px;"
> class="dotline"></td>
> </tr>
> <tr>
> <td style="height:10px;"
> align="right"></td>
> </tr>
> </table>
> </td>
> </tr>
> <tr>
> <td>
> <uc:CompanyTabs ID="CompanyTabs" runat="server"
> />
> </td>
> </tr>
> </table>
> <table id="tableDepartments" runat="server" width="100%"
> border="0" cellspacing="0" cellpadding="0" style="padding-left: 10px;
> padding-right: 10px;">
> <tr>
> <td>
> <table width="100%" border="0" cellpadding="0"
> cellspacing="0">
> <tr>
> <td style="height:5px;"></td>
> </tr>
> <tr>
> <td class="textsubheading">Departments
> Info</td>
> <td align="right"><asp:LinkButton
> ID="DPAddNew" runat="server" Text="Add New" CssClass="but_sub"
> Height="18" Width="60" OnClientClick="showWrap('divWrap', false);"
> OnClick="DPAddNew_Click"></asp:LinkButton>&nbsp;<asp:LinkButton
> ID="DPEdit" runat="server" Text="Edit" CssClass="but_sub" Height="18"
> Width="60" OnClientClick="showWrap('divWrap',true);"
> OnClick="DPEdit_Click"></asp:LinkButton>&nbsp;<asp:LinkButton
> ID="DPDelete" runat="server" Text="Delete" CssClass="but_sub"
> Height="18" Width="60" OnClientClick="showWrap('divWrap',true);"
> onClick="DPDelete_Click"></asp:LinkButton></td>
> </tr>
> <tr>
> <td colspan="2">
> <asp:GridView SkinID="List"
> ID="DPGridView" runat="server"
> DataKeyNames="HDepartmentId,HLocationId,HCompanyId ,HDivisionId,Departmen
> tName,DepartmentCode,LocationName" OnDataBound="DPGridView_OnDataBound">
>
> <Columns>
> <asp:BoundField
> HeaderText="Company" DataField="CompanyName" ItemStyle-Width="19%" />
> <asp:BoundField
> HeaderText="LocationName" DataField="LocationName" ItemStyle-Width="19%"
> />
> <asp:BoundField
> HeaderText="DivisionName" DataField="DivisionName" ItemStyle-Width="19%"
> />
> <asp:BoundField
> HeaderText="DepartmentName" DataField="DepartmentName"
> ItemStyle-Width="24%" />
> </Columns>
> </asp:GridView>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> <tr>
> <td style="height:5px;"></td>
> </tr>
> </table>
> <div id="divDepartmentsInfo" runat="server"
> class="divContent" visible="false">
> <table class="tableContent" cellSpacing=0 cellPadding=0>
> <tr class="trContent">
> <td align=left
> style="padding-left:5px;">Add/Edit Departments Info</td>
> <td align=right>
> <asp:LinkButton id="lnkAClose"
> onclick="lnkAClose_Click" runat="server" Text="X" CssClass=""
> CausesValidation="False" OnClientClick="hideWrap('divWrap');"
> ToolTip="Close"></asp:LinkButton>&nbsp;
> </td>
> </tr>
> <tr>
> <td style="height:5px;"></td>
> </tr>
> <tr>
> <td colspan=2>
> <div style="OVERFLOW: auto; WIDTH: 700px;
> HEIGHT: 300px";>
> <table width="100%" border="0"
> cellspacing="0" cellpadding="0">
> <tr>
> <td colspan="2"
> style="height:9px; padding-left:3px;"><asp:ValidationSummary
> ValidationGroup="Departments" ID="vsDepartments" runat="server"
> HeaderText="Invalid Values: " DisplayMode="SingleParagraph" /></td>
> </tr>
> <tr>
> <td style="height:15px;"></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align="right">Select Company:&nbsp;</td>
> <td><aspropDownList
> id="ddlSelectCompany" runat="server" CssClass="textboxmust"
> Width="115px" DataTextField="CompanyName" DataValueField="HCompanyId"
> TabIndex="1" AutoPostBack=true
> OnSelectedIndexChanged="ddlSelectCompany_SelectedI ndexChanged"
> AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
> or ID="rfvSelectCompany" runat="Server" ValidationGroup="Departments"
> ControlToValidate="ddlSelectCompany" ErrorMessage="Company;"
> ToolTip="Select Company.">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align=right>Select Location:&nbsp;</td>
> <td><aspropDownList
> id="ddlSelectLocation" runat="server" CssClass="textboxmust"
> Width="115px" DataTextField="LocationName" DataValueField="HLocationId"
> TabIndex="2" AutoPostBack=true
> OnSelectedIndexChanged="ddlSelectLocation_Selected IndexChanged"
> AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
> or ID="rfvSelectLocation" runat="Server" ValidationGroup="Departments"
> ControlToValidate="ddlSelectLocation" ErrorMessage="Location;"
> ToolTip="Select Location."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align=right>Select Division:&nbsp;</td>
> <td><aspropDownList
> id="ddlSelectDivision" runat="server" CssClass="textboxmust"
> Width="115px" DataTextField="DivisionName" DataValueField="HDivisionId"
> TabIndex="2" AutoPostBack=true
> AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
> or ID="rfvSelectDivision" runat="Server" ValidationGroup="Departments"
> ControlToValidate="ddlSelectDivision" ErrorMessage="Division;"
> ToolTip="Select Division."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align="right">Department Name:&nbsp;</td>
> <td><asp:TextBox
> ID="txtDepartmentName" runat="server" CssClass="textboxmust"
> TabIndex="3"></asp:TextBox><asp:RequiredFieldValidator
> ID="rfvtxtDepartmentName" runat="Server" ValidationGroup="Departments"
> ControlToValidate="txtDepartmentName" ErrorMessage="Department;"
> ToolTip="Enter Department."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
>
> <tr>
> <td style="height:22px;"
> align="right">Code #:&nbsp;</td>
> <td><asp:TextBox
> ID="txtDepartmentCode" runat="server" CssClass="textboxmust"
> TabIndex="5"></asp:TextBox><asp:RequiredFieldValidator
> ID="rfvDepartmentCode" runat="server" ValidationGroup="Departments"
> ControlToValidate="txtDepartmentCode" ErrorMessage="Code;"
> ToolTip="Enter Department Code."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:15px;"></td>
> </tr>
> <tr>
> <td colspan=1 ></td>
> <td
> style="height:22px;"><asp:LinkButton ValidationGroup="Departments"
> ID="DPInsert" runat="server" Text="Insert" CssClass="but_sub"
> Height="18" Width="60" OnClientClick="showWrap('divWrapC',true);"
> onClick="DPInsert_Click" TabIndex="9"></asp:LinkButton><asp:LinkButton
> ValidationGroup="Departments" ID="DPUpdate" runat="server" Text="Update"
> CssClass="but_sub" Height="18" Width="60"
> OnClientClick="showWrap('divWrapC',true);" onClick="DPUpdate_Click"
> TabIndex="9"></asp:LinkButton>&nbsp;<asp:LinkButton
> CausesValidation="false" ID="DPCancel" runat="server" Text="Cancel"
> CssClass="but_sub" Height="18" Width="60"
> OnClientClick="hideWrap('divWrap');" OnClick="DPCancel_Click"
> TabIndex="10"></asp:LinkButton></td>
> </tr>
> </table>
> </div>
> </td>
> </tr>
> </table>
> </div>
>
> </ContentTemplate>
> </asp:UpdatePanel>
> </asp:Content>
>
> *** Sent via Developersdexhttp://www.developersdex.com***


So, what's the problem?

 
Reply With Quote
 
 
 
 
David C
Guest
Posts: n/a
 
      06-22-2007
You might want to look at the property AppendDataBoundItems in the drop down
list control. You can create a blank (null) or?? entry that will handle
missing items.

hth
David
"sree reddy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> cs
>
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
> using System.Data.Sql;
> using System.Data.SqlClient;
>
> public partial class CompanyDepartments : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> if (!IsPostBack)
> {
>
> ((LinkButton)CompanyTabs.FindControl("LinkButton4" )).CssClass =
> "tabselected";
> ((TableCell)CompanyTabs.FindControl("TableCell10") ).CssClass
> = "tabselectedl";
> ((TableCell)CompanyTabs.FindControl("TableCell11") ).CssClass
> = "tabselected";
> ((TableCell)CompanyTabs.FindControl("TableCell12") ).CssClass
> = "tabselectedr";
>
> this.BindDPGridView();
>
> ddlSelectCompany.DataSource =
> PMPro.BusinessClasses.HRCompany.SelectAllHRCompany ByDescription_DataRead
> er();
> ddlSelectCompany.DataBind();
> ddlSelectCompany.Items.Insert(0, new ListItem("--", ""));
>
> ddlSelectDivision.DataSource =
> PMPro.BusinessClasses.HRDivisions.SelectAllHRDivis ionsByDescription_Data
> Reader();
> ddlSelectDivision.DataBind();
> ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
>
> ddlSelectLocation.DataSource =
> PMPro.BusinessClasses.HRLocations.SelectAllHRLocat ionByDescription_DataR
> eader();
> ddlSelectLocation.DataBind();
> ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));
>
>
> }
> }
> protected override void Render(HtmlTextWriter writer)
> {
> if (DPGridView.Rows.Count > 0)
> {
> foreach (GridViewRow row in DPGridView.Rows)
> {
> if (row.RowType == DataControlRowType.DataRow)
> {
> row.Attributes.Add("onclick",
> Page.ClientScript.GetPostBackEventReference(DPGrid View, "Select$" +
> row.RowIndex.ToString(), true));
> }
> }
> }
>
> base.Render(writer);
> }
>
> protected void lnkConfirmY1_Click(object sender, EventArgs e)
> {
> divConfirm.Visible = false;
> }
>
>
> protected void lnkErrorY1_Click(object sender, EventArgs e)
> {
> divConfirm.Visible = false;
> }
>
>
> private void ClearControls()
> {
> txtDepartmentName.Text = "";
> txtDepartmentCode.Text = "";
> ddlSelectCompany.ClearSelection();
> ddlSelectDivision.ClearSelection();
> }
>
> private void BindDPGridView()
> {
> //if (Request.QueryString["HDepartmentId"] != null &&
> Request.QueryString["HDepartmentId"].ToString() != "")
> //{
> DPGridView.DataSource =
> PMPro.BusinessClasses.HRDepartments.SelectAllHRDep artmentsTypesByHRDepar
> tmentsTypeId_DataTable();
> DPGridView.DataBind();
> DPGridView.SelectedIndex = 0;
> //}
> }
> protected void DPGridView_OnDataBound(object sender, EventArgs e)
> {
> if (DPGridView.Rows.Count > 0)
> {
> DPEdit.Visible = true;
> DPDelete.Visible = true;
> }
> else
> {
> DPEdit.Visible = false;
> DPDelete.Visible = false;
> }
> }
>
> protected void DPAddNew_Click(object sender, EventArgs e)
> {
> this.ClearControls();
> divDepartmentsInfo.Visible = true;
> DPInsert.Visible = true;
> DPUpdate.Visible = false;
> }
> protected void DPEdit_Click(object sender, EventArgs e)
> {
> if (DPGridView.SelectedValue != null)
> {
> this.FillDPControls();
> divDepartmentsInfo.Visible = true;
> DPInsert.Visible = false;
> DPUpdate.Visible = true;
>
> }
>
> }
> protected void DPDelete_Click(object sender, EventArgs e)
> {
> if (DPGridView.SelectedValue != null)
> {
> delConfirm.Visible = true;
> DPYes.Visible = true;
> lblConfirmDel.Text =
> string.Format(Resources.Resource.MSG_ITEM_DELETE_C ONFIRMATION," "+
> "Company / Locations Department : " +
> DPGridView.DataKeys[DPGridView.SelectedIndex].Values["DepartmentName"].T
> oString() + "</b>");
> }
> }
> private void DPConfirmationActions(string ErrorMessage, LinkButton
> VisibleLink, bool IsSuccess)
> {
> divConfirm.Visible = true;
> lnkConfirmY1.Visible = false;
> lnkErrorY1.Visible = false;
> VisibleLink.Visible = true;
> if (IsSuccess)
> {
> ImgConfirm.ImageUrl =
> "~/App_Themes/Blue/Images/correct.gif";
> }
> else
> {
> ImgConfirm.ImageUrl = "~/App_Themes/Blue/Images/error.gif";
> }
> lblConfirm.Text = ErrorMessage;
> }
>
> protected void DPInsert_Click(object sender, EventArgs e)
> {
>
> object HCompanyId = null; if
> (ddlSelectCompany.SelectedValue.Length > 0) { HCompanyId =
> Int32.Parse(ddlSelectCompany.SelectedValue); }
> object HLocationId = null; if
> (ddlSelectLocation.SelectedValue.Length > 0) { HLocationId =
> Int32.Parse(ddlSelectLocation.SelectedValue); }
> object HDivisionId = null; if
> (ddlSelectDivision.SelectedValue.Length > 0) { HDivisionId =
> Int32.Parse(ddlSelectDivision.SelectedValue); }
> object DepartmentName = null; if
> (txtDepartmentName.Text.Trim().Length > 0) { DepartmentName =
> txtDepartmentName.Text.Trim(); }
> object DepartmentCode = null; if
> (txtDepartmentCode.Text.Trim().Length > 0) { DepartmentCode =
> txtDepartmentCode.Text.Trim(); }
> Int16 RecordStatus =
> PMPro.BusinessClasses.HRDepartments.Insert(HCompan yId, HLocationId,
> HDivisionId, txtDepartmentName.Text.Trim(),
> txtDepartmentCode.Text.Trim());
>
> divConfirm.Visible = true;
>
>
> if (RecordStatus == 1)
> {
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_ADD
> , "DepartmentName"), lnkConfirmY1, true);
> divDepartmentsInfo.Visible = false;
> this.ClearControls();
> this.BindDPGridView();
>
> }
> if (RecordStatus == 0)
> {
> lblConfirm.Text =
> string.Format(Resources.Resource.MSG_ITEM_ALREADY_ EXISTS, "Information",
> "Name");
>
> }
> }
>
> protected void DPUpdate_Click(object sender, EventArgs e)
> {
>
> object DepartmentName = null; if
> (txtDepartmentName.Text.Trim().Length > 0) { DepartmentName =
> txtDepartmentName.Text.Trim(); }
> object DepartmentCode = null; if
> (txtDepartmentCode.Text.Trim().Length > 0) { DepartmentCode =
> txtDepartmentCode.Text.Trim(); }
> Int16 RecordStatus =
> PMPro.BusinessClasses.HRDepartments.Update((Int32) DPGridView.SelectedVal
> ue, Int32.Parse(ddlSelectCompany.SelectedValue),
> Int32.Parse(ddlSelectLocation.SelectedValue),
> Int32.Parse(ddlSelectDivision.SelectedValue),
> txtDepartmentName.Text.Trim(), txtDepartmentCode.Text.Trim());
>
> divConfirm.Visible = true;
>
>
> if (RecordStatus == 1)
> {
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_UPD
> ATE, "Department"), lnkConfirmY1, true);
> divDepartmentsInfo.Visible = false;
> this.ClearControls();
> this.BindDPGridView();
> }
> else
> {
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_ALR
> EADY_EXISTS1, txtDepartmentName.Text + "Department Information"),
> lnkErrorY1, false);
> }
> }
> protected void DPYes_Click(object sender, EventArgs e)
> {
>
> PMPro.BusinessClasses.HRDepartments.Delete((Int32) (DPGridView.SelectedVa
> lue));
>
> divDepartmentsInfo.Visible = false;
> delConfirm.Visible = false;
>
>
> this.DPConfirmationActions(string.Format(Resources .Resource.MSG_ITEM_DEL
> ETE, "DepartmentTypes"), lnkConfirmY1, true);
>
> this.BindDPGridView();
> }
> protected void No_Click(object sender, EventArgs e)
> {
> delConfirm.Visible = false;
> }
> protected void lnkAClose_Click(object sender, EventArgs e)
> {
> divDepartmentsInfo.Visible = false;
> }
> protected void DPCancel_Click(object sender, EventArgs e)
> {
> divDepartmentsInfo.Visible = false;
> }
>
> private void FillDPControls()
> {
> if (DPGridView.SelectedValue != null)
> {
> int Index = DPGridView.SelectedIndex;
>
> ddlSelectCompany.SelectedValue =
> DPGridView.DataKeys[Index].Values["HCompanyId"].ToString();
>
> ddlSelectLocation.SelectedValue =
> DPGridView.DataKeys[Index].Values["HLocationId"].ToString();
> ddlSelectDivision.SelectedValue=
> DPGridView.DataKeys[Index].Values["HDivisionId"].ToString();
> txtDepartmentName.Text=
> DPGridView.DataKeys[Index].Values["DepartmentName"].ToString();
> txtDepartmentCode.Text=
> DPGridView.DataKeys[Index].Values["DepartmentCode"].ToString();
>
> }
>
> }
> protected void ddlSelectCompany_SelectedIndexChanged(object sender,
> EventArgs e)
> {
>
> ddlSelectLocation.Items.Clear();
> ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));
>
> if (ddlSelectCompany.SelectedValue != "")
> {
> ddlSelectLocation.DataSource =
> PMPro.BusinessClasses.HRPersonLocations.SelectAllP ersonAccessibleLocatio
> nsByPersonId_DataReader(Int32.Parse(ddlSelectCompa ny.SelectedValue));
> ddlSelectLocation.DataBind();
> ddlSelectLocation.Items.Insert(0, new ListItem("--", ""));
>
> }
> }
> protected void ddlSelectLocation_SelectedIndexChanged(object sender,
> EventArgs e)
> {
>
> ddlSelectDivision.Items.Clear();
> ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
>
> if (ddlSelectLocation.SelectedValue != "")
> {
> ddlSelectDivision.DataSource =
> PMPro.BusinessClasses.HRDivisions.SelectAllPersonA ccessibleDivisionsByPe
> rsonId_DataReader(Int32.Parse(ddlSelectLocation.Se lectedValue));
> ddlSelectDivision.DataBind();
> ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
>
> }
> }
> }
>
>
> aspx
>
> <%@ Page Language="C#" MasterPageFile="~/Master/Sub.master"
> AutoEventWireup="true" CodeFile="CompanyDepartments.aspx.cs"
> Inherits="CompanyDepartments" Theme="Blue" %>
> <%@ Register TagPrefix="uc" TagName=CompanyTabs
> Src="~/Controls/CompanyTabs.ascx" %>
> <asp:Content ID="Content1" ContentPlaceHolderID="CPH1" Runat="Server">
> <div id="divWrapC" class="divWrapperC"></div>
> <asp:UpdatePanel ID="GVPanel" runat="server">
> <ContentTemplate>
> <DIV id="divConfirm" class="divConfirm" runat="server"
> visible="false">
> <table class="tableContent" cellSpacing=0 cellPadding=0
> width="500px">
> <tr class="trContent">
> <td align=left colspan="2"
> style="padding-left:5px;">Confirmation</td>
> </tr>
> <tr style="height:85px;">
> <td style="width:25%;" align="center"
> valign="middle"><asp:Image id="ImgConfirm" runat="server" /></td>
> <td align="left" valign="middle"
> style="padding-right:5px;" >
> <asp:Label id="lblConfirm"
> runat="server"></asp:Label>
> </td>
> </tr>
> <tr>
> <td align="center" valign="top" colspan="2">
> <asp:LinkButton CausesValidation="false"
> id="lnkConfirmY1" onclick="lnkConfirmY1_Click" runat="server" Text="OK"
> CssClass="but_sub"
> OnClientClick="hideWrap('divWrap');hideWrap('divWr apC');" Height="18"
> Width="60"></asp:LinkButton>
> <asp:LinkButton CausesValidation="false"
> id="lnkErrorY1" onclick="lnkErrorY1_Click" runat="server" Text="OK"
> CssClass="but_sub" OnClientClick="hideWrap('divWrapC');" Height="18"
> Width="60"></asp:LinkButton>
> </td>
> </tr>
> </table>
> </div>
> <DIV id="delConfirm" class="divContent" runat="server"
> visible="false">
> <table class="tableContent" cellSpacing=0 cellPadding=0>
> <TR class="trContent">
> <td align=left style="padding-left:5px;"></td>
> </tr>
> <tr>
> <td>
> <DIV style="OVERFLOW: auto; WIDTH:500px;
> HEIGHT:120px;">
> <table width="100%" >
> <tr height="85px">
> <td align="center">
> <asp:Label
> id="lblConfirmDel" runat="server"></asp:Label>
> </td>
> </tr>
> <tr>
> <td align="center">
> <asp:LinkButton id="DPYes"
> runat="server" Text="Yes" CssClass="but_sub" Height="18" Width="60"
> OnClientClick="showWrap('divWrapC', false);"
> onClick="DPYes_Click"></asp:LinkButton>
> &nbsp;<asp:LinkButton
> id="No" onClick="No_Click" runat="server" Text="No" CssClass="but_sub"
> OnClientClick="hideWrap('divWrap');" Height="18"
> Width="60"></asp:LinkButton>
> </td>
> </tr>
> </table>
> </div>
> </td>
> </tr>
> </table>
> </div>
> <table width="100%" border="0" cellspacing="0"
> cellpadding="0" style="padding-left: 10px; padding-right: 10px;">
> <tr>
> <td>
> <table width="100%" border="0" cellspacing="0"
> cellpadding="0">
> <tr>
> <td style="height:18px;" valign="bottom"
> class="textheading">Company Setup</td>
> </tr>
> <tr>
> <td style="height:1px;"
> class="dotline"></td>
> </tr>
> <tr>
> <td style="height:10px;"
> align="right"></td>
> </tr>
> </table>
> </td>
> </tr>
> <tr>
> <td>
> <uc:CompanyTabs ID="CompanyTabs" runat="server"
> />
> </td>
> </tr>
> </table>
> <table id="tableDepartments" runat="server" width="100%"
> border="0" cellspacing="0" cellpadding="0" style="padding-left: 10px;
> padding-right: 10px;">
> <tr>
> <td>
> <table width="100%" border="0" cellpadding="0"
> cellspacing="0">
> <tr>
> <td style="height:5px;"></td>
> </tr>
> <tr>
> <td class="textsubheading">Departments
> Info</td>
> <td align="right"><asp:LinkButton
> ID="DPAddNew" runat="server" Text="Add New" CssClass="but_sub"
> Height="18" Width="60" OnClientClick="showWrap('divWrap', false);"
> OnClick="DPAddNew_Click"></asp:LinkButton>&nbsp;<asp:LinkButton
> ID="DPEdit" runat="server" Text="Edit" CssClass="but_sub" Height="18"
> Width="60" OnClientClick="showWrap('divWrap',true);"
> OnClick="DPEdit_Click"></asp:LinkButton>&nbsp;<asp:LinkButton
> ID="DPDelete" runat="server" Text="Delete" CssClass="but_sub"
> Height="18" Width="60" OnClientClick="showWrap('divWrap',true);"
> onClick="DPDelete_Click"></asp:LinkButton></td>
> </tr>
> <tr>
> <td colspan="2">
> <asp:GridView SkinID="List"
> ID="DPGridView" runat="server"
> DataKeyNames="HDepartmentId,HLocationId,HCompanyId ,HDivisionId,Departmen
> tName,DepartmentCode,LocationName" OnDataBound="DPGridView_OnDataBound">
>
> <Columns>
> <asp:BoundField
> HeaderText="Company" DataField="CompanyName" ItemStyle-Width="19%" />
> <asp:BoundField
> HeaderText="LocationName" DataField="LocationName" ItemStyle-Width="19%"
> />
> <asp:BoundField
> HeaderText="DivisionName" DataField="DivisionName" ItemStyle-Width="19%"
> />
> <asp:BoundField
> HeaderText="DepartmentName" DataField="DepartmentName"
> ItemStyle-Width="24%" />
> </Columns>
> </asp:GridView>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> <tr>
> <td style="height:5px;"></td>
> </tr>
> </table>
> <div id="divDepartmentsInfo" runat="server"
> class="divContent" visible="false">
> <table class="tableContent" cellSpacing=0 cellPadding=0>
> <tr class="trContent">
> <td align=left
> style="padding-left:5px;">Add/Edit Departments Info</td>
> <td align=right>
> <asp:LinkButton id="lnkAClose"
> onclick="lnkAClose_Click" runat="server" Text="X" CssClass=""
> CausesValidation="False" OnClientClick="hideWrap('divWrap');"
> ToolTip="Close"></asp:LinkButton>&nbsp;
> </td>
> </tr>
> <tr>
> <td style="height:5px;"></td>
> </tr>
> <tr>
> <td colspan=2>
> <div style="OVERFLOW: auto; WIDTH: 700px;
> HEIGHT: 300px";>
> <table width="100%" border="0"
> cellspacing="0" cellpadding="0">
> <tr>
> <td colspan="2"
> style="height:9px; padding-left:3px;"><asp:ValidationSummary
> ValidationGroup="Departments" ID="vsDepartments" runat="server"
> HeaderText="Invalid Values: " DisplayMode="SingleParagraph" /></td>
> </tr>
> <tr>
> <td style="height:15px;"></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align="right">Select Company:&nbsp;</td>
> <td><aspropDownList
> id="ddlSelectCompany" runat="server" CssClass="textboxmust"
> Width="115px" DataTextField="CompanyName" DataValueField="HCompanyId"
> TabIndex="1" AutoPostBack=true
> OnSelectedIndexChanged="ddlSelectCompany_SelectedI ndexChanged"
> AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
> or ID="rfvSelectCompany" runat="Server" ValidationGroup="Departments"
> ControlToValidate="ddlSelectCompany" ErrorMessage="Company;"
> ToolTip="Select Company.">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align=right>Select Location:&nbsp;</td>
> <td><aspropDownList
> id="ddlSelectLocation" runat="server" CssClass="textboxmust"
> Width="115px" DataTextField="LocationName" DataValueField="HLocationId"
> TabIndex="2" AutoPostBack=true
> OnSelectedIndexChanged="ddlSelectLocation_Selected IndexChanged"
> AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
> or ID="rfvSelectLocation" runat="Server" ValidationGroup="Departments"
> ControlToValidate="ddlSelectLocation" ErrorMessage="Location;"
> ToolTip="Select Location."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align=right>Select Division:&nbsp;</td>
> <td><aspropDownList
> id="ddlSelectDivision" runat="server" CssClass="textboxmust"
> Width="115px" DataTextField="DivisionName" DataValueField="HDivisionId"
> TabIndex="2" AutoPostBack=true
> AppendDataBoundItems="True"></aspropDownList><asp:RequiredFieldValidat
> or ID="rfvSelectDivision" runat="Server" ValidationGroup="Departments"
> ControlToValidate="ddlSelectDivision" ErrorMessage="Division;"
> ToolTip="Select Division."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:22px;"
> align="right">Department Name:&nbsp;</td>
> <td><asp:TextBox
> ID="txtDepartmentName" runat="server" CssClass="textboxmust"
> TabIndex="3"></asp:TextBox><asp:RequiredFieldValidator
> ID="rfvtxtDepartmentName" runat="Server" ValidationGroup="Departments"
> ControlToValidate="txtDepartmentName" ErrorMessage="Department;"
> ToolTip="Enter Department."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
>
> <tr>
> <td style="height:22px;"
> align="right">Code #:&nbsp;</td>
> <td><asp:TextBox
> ID="txtDepartmentCode" runat="server" CssClass="textboxmust"
> TabIndex="5"></asp:TextBox><asp:RequiredFieldValidator
> ID="rfvDepartmentCode" runat="server" ValidationGroup="Departments"
> ControlToValidate="txtDepartmentCode" ErrorMessage="Code;"
> ToolTip="Enter Department Code."
> SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="height:15px;"></td>
> </tr>
> <tr>
> <td colspan=1 ></td>
> <td
> style="height:22px;"><asp:LinkButton ValidationGroup="Departments"
> ID="DPInsert" runat="server" Text="Insert" CssClass="but_sub"
> Height="18" Width="60" OnClientClick="showWrap('divWrapC',true);"
> onClick="DPInsert_Click" TabIndex="9"></asp:LinkButton><asp:LinkButton
> ValidationGroup="Departments" ID="DPUpdate" runat="server" Text="Update"
> CssClass="but_sub" Height="18" Width="60"
> OnClientClick="showWrap('divWrapC',true);" onClick="DPUpdate_Click"
> TabIndex="9"></asp:LinkButton>&nbsp;<asp:LinkButton
> CausesValidation="false" ID="DPCancel" runat="server" Text="Cancel"
> CssClass="but_sub" Height="18" Width="60"
> OnClientClick="hideWrap('divWrap');" OnClick="DPCancel_Click"
> TabIndex="10"></asp:LinkButton></td>
> </tr>
> </table>
> </div>
> </td>
> </tr>
> </table>
> </div>
>
> </ContentTemplate>
> </asp:UpdatePanel>
> </asp:Content>
>
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectedValue which is invalid because it does not exist in the list of items. far ASP .Net 5 01-14-2012 05:47 PM
Any good solutions for: SelectedValue which is invalid because it does not exist in the list of items? randy.buchholz ASP .Net 4 07-16-2008 03:45 PM
System.ArgumentOutOfRangeException: 'DropDownList' has a SelectedValue which is invalid because it does not exist in the list of items. J055 ASP .Net 4 11-14-2007 03:08 AM
dropdownlist has a selectedvalue which is invalid because it does not exist in the list of items. Jason ASP .Net 0 08-07-2007 07:35 PM
Avoiding "SelectedValue which is invalid because it does not exist in the list of items" Dave ASP .Net 2 06-30-2007 05:15 PM



Advertisments