473,558 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


..cs

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Sql ;
using System.Data.Sql Client;

public partial class CompanyDepartme nts : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{

((LinkButton)Co mpanyTabs.FindC ontrol("LinkBut ton4")).CssClas s =
"tabselecte d";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l10")).CssClas s
= "tabselecte dl";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l11")).CssClas s
= "tabselecte d";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l12")).CssClas s
= "tabselecte dr";

this.BindDPGrid View();

ddlSelectCompan y.DataSource =
PMPro.BusinessC lasses.HRCompan y.SelectAllHRCo mpanyByDescript ion_DataRead
er();
ddlSelectCompan y.DataBind();
ddlSelectCompan y.Items.Insert( 0, new ListItem("--", ""));

ddlSelectDivisi on.DataSource =
PMPro.BusinessC lasses.HRDivisi ons.SelectAllHR DivisionsByDesc ription_Data
Reader();
ddlSelectDivisi on.DataBind();
ddlSelectDivisi on.Items.Insert (0, new ListItem("--", ""));

ddlSelectLocati on.DataSource =
PMPro.BusinessC lasses.HRLocati ons.SelectAllHR LocationByDescr iption_DataR
eader();
ddlSelectLocati on.DataBind();
ddlSelectLocati on.Items.Insert (0, new ListItem("--", ""));
}
}
protected override void Render(HtmlText Writer writer)
{
if (DPGridView.Row s.Count 0)
{
foreach (GridViewRow row in DPGridView.Rows )
{
if (row.RowType == DataControlRowT ype.DataRow)
{
row.Attributes. Add("onclick",
Page.ClientScri pt.GetPostBackE ventReference(D PGridView, "Select$" +
row.RowIndex.To String(), true));
}
}
}

base.Render(wri ter);
}

protected void lnkConfirmY1_Cl ick(object sender, EventArgs e)
{
divConfirm.Visi ble = false;
}
protected void lnkErrorY1_Clic k(object sender, EventArgs e)
{
divConfirm.Visi ble = false;
}
private void ClearControls()
{
txtDepartmentNa me.Text = "";
txtDepartmentCo de.Text = "";
ddlSelectCompan y.ClearSelectio n();
ddlSelectDivisi on.ClearSelecti on();
}

private void BindDPGridView( )
{
//if (Request.QueryS tring["HDepartmen tId"] != null &&
Request.QuerySt ring["HDepartmen tId"].ToString() != "")
//{
DPGridView.Data Source =
PMPro.BusinessC lasses.HRDepart ments.SelectAll HRDepartmentsTy pesByHRDepar
tmentsTypeId_Da taTable();
DPGridView.Data Bind();
DPGridView.Sele ctedIndex = 0;
//}
}
protected void DPGridView_OnDa taBound(object sender, EventArgs e)
{
if (DPGridView.Row s.Count 0)
{
DPEdit.Visible = true;
DPDelete.Visibl e = true;
}
else
{
DPEdit.Visible = false;
DPDelete.Visibl e = false;
}
}

protected void DPAddNew_Click( object sender, EventArgs e)
{
this.ClearContr ols();
divDepartmentsI nfo.Visible = true;
DPInsert.Visibl e = true;
DPUpdate.Visibl e = false;
}
protected void DPEdit_Click(ob ject sender, EventArgs e)
{
if (DPGridView.Sel ectedValue != null)
{
this.FillDPCont rols();
divDepartmentsI nfo.Visible = true;
DPInsert.Visibl e = false;
DPUpdate.Visibl e = true;

}

}
protected void DPDelete_Click( object sender, EventArgs e)
{
if (DPGridView.Sel ectedValue != null)
{
delConfirm.Visi ble = true;
DPYes.Visible = true;
lblConfirmDel.T ext =
string.Format(R esources.Resour ce.MSG_ITEM_DEL ETE_CONFIRMATIO N," "+
"Company / Locations Department : " +
DPGridView.Data Keys[DPGridView.Sele ctedIndex].Values["DepartmentName "].T
oString() + "</b>");
}
}
private void DPConfirmationA ctions(string ErrorMessage, LinkButton
VisibleLink, bool IsSuccess)
{
divConfirm.Visi ble = true;
lnkConfirmY1.Vi sible = false;
lnkErrorY1.Visi ble = false;
VisibleLink.Vis ible = true;
if (IsSuccess)
{
ImgConfirm.Imag eUrl =
"~/App_Themes/Blue/Images/correct.gif";
}
else
{
ImgConfirm.Imag eUrl = "~/App_Themes/Blue/Images/error.gif";
}
lblConfirm.Text = ErrorMessage;
}

protected void DPInsert_Click( object sender, EventArgs e)
{

object HCompanyId = null; if
(ddlSelectCompa ny.SelectedValu e.Length 0) { HCompanyId =
Int32.Parse(ddl SelectCompany.S electedValue); }
object HLocationId = null; if
(ddlSelectLocat ion.SelectedVal ue.Length 0) { HLocationId =
Int32.Parse(ddl SelectLocation. SelectedValue); }
object HDivisionId = null; if
(ddlSelectDivis ion.SelectedVal ue.Length 0) { HDivisionId =
Int32.Parse(ddl SelectDivision. SelectedValue); }
object DepartmentName = null; if
(txtDepartmentN ame.Text.Trim() .Length 0) { DepartmentName =
txtDepartmentNa me.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentC ode.Text.Trim() .Length 0) { DepartmentCode =
txtDepartmentCo de.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessC lasses.HRDepart ments.Insert(HC ompanyId, HLocationId,
HDivisionId, txtDepartmentNa me.Text.Trim(),
txtDepartmentCo de.Text.Trim()) ;

divConfirm.Visi ble = true;
if (RecordStatus == 1)
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_ADD
, "DepartmentName "), lnkConfirmY1, true);
divDepartmentsI nfo.Visible = false;
this.ClearContr ols();
this.BindDPGrid View();

}
if (RecordStatus == 0)
{
lblConfirm.Text =
string.Format(R esources.Resour ce.MSG_ITEM_ALR EADY_EXISTS, "Informatio n",
"Name");

}
}

protected void DPUpdate_Click( object sender, EventArgs e)
{

object DepartmentName = null; if
(txtDepartmentN ame.Text.Trim() .Length 0) { DepartmentName =
txtDepartmentNa me.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentC ode.Text.Trim() .Length 0) { DepartmentCode =
txtDepartmentCo de.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessC lasses.HRDepart ments.Update((I nt32)DPGridView .SelectedVal
ue, Int32.Parse(ddl SelectCompany.S electedValue),
Int32.Parse(ddl SelectLocation. SelectedValue),
Int32.Parse(ddl SelectDivision. SelectedValue),
txtDepartmentNa me.Text.Trim(), txtDepartmentCo de.Text.Trim()) ;

divConfirm.Visi ble = true;
if (RecordStatus == 1)
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_UPD
ATE, "Department "), lnkConfirmY1, true);
divDepartmentsI nfo.Visible = false;
this.ClearContr ols();
this.BindDPGrid View();
}
else
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_ALR
EADY_EXISTS1, txtDepartmentNa me.Text + "Department Information"),
lnkErrorY1, false);
}
}
protected void DPYes_Click(obj ect sender, EventArgs e)
{

PMPro.BusinessC lasses.HRDepart ments.Delete((I nt32)(DPGridVie w.SelectedVa
lue));

divDepartmentsI nfo.Visible = false;
delConfirm.Visi ble = false;
this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_DEL
ETE, "DepartmentType s"), lnkConfirmY1, true);

this.BindDPGrid View();
}
protected void No_Click(object sender, EventArgs e)
{
delConfirm.Visi ble = false;
}
protected void lnkAClose_Click (object sender, EventArgs e)
{
divDepartmentsI nfo.Visible = false;
}
protected void DPCancel_Click( object sender, EventArgs e)
{
divDepartmentsI nfo.Visible = false;
}

private void FillDPControls( )
{
if (DPGridView.Sel ectedValue != null)
{
int Index = DPGridView.Sele ctedIndex;

ddlSelectCompan y.SelectedValue =
DPGridView.Data Keys[Index].Values["HCompanyId "].ToString();

ddlSelectLocati on.SelectedValu e =
DPGridView.Data Keys[Index].Values["HLocationI d"].ToString();
ddlSelectDivisi on.SelectedValu e=
DPGridView.Data Keys[Index].Values["HDivisionI d"].ToString();
txtDepartmentNa me.Text=
DPGridView.Data Keys[Index].Values["DepartmentName "].ToString();
txtDepartmentCo de.Text=
DPGridView.Data Keys[Index].Values["DepartmentCode "].ToString();

}

}
protected void ddlSelectCompan y_SelectedIndex Changed(object sender,
EventArgs e)
{

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

if (ddlSelectCompa ny.SelectedValu e != "")
{
ddlSelectLocati on.DataSource =
PMPro.BusinessC lasses.HRPerson Locations.Selec tAllPersonAcces sibleLocatio
nsByPersonId_Da taReader(Int32. Parse(ddlSelect Company.Selecte dValue));
ddlSelectLocati on.DataBind();
ddlSelectLocati on.Items.Insert (0, new ListItem("--", ""));

}
}
protected void ddlSelectLocati on_SelectedInde xChanged(object sender,
EventArgs e)
{

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

if (ddlSelectLocat ion.SelectedVal ue != "")
{
ddlSelectDivisi on.DataSource =
PMPro.BusinessC lasses.HRDivisi ons.SelectAllPe rsonAccessibleD ivisionsByPe
rsonId_DataRead er(Int32.Parse( ddlSelectLocati on.SelectedValu e));
ddlSelectDivisi on.DataBind();
ddlSelectDivisi on.Items.Insert (0, new ListItem("--", ""));

}
}
}
..aspx

<%@ Page Language="C#" MasterPageFile= "~/Master/Sub.master"
AutoEventWireup ="true" CodeFile="Compa nyDepartments.a spx.cs"
Inherits="Compa nyDepartments" Theme="Blue" %>
<%@ Register TagPrefix="uc" TagName=Company Tabs
Src="~/Controls/CompanyTabs.asc x" %>
<asp:Content ID="Content1" ContentPlaceHol derID="CPH1" Runat="Server">
<div id="divWrapC" class="divWrapp erC"></div>
<asp:UpdatePane l ID="GVPanel" runat="server">
<ContentTemplat e>
<DIV id="divConfirm " class="divConfi rm" runat="server"
visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0
width="500px">
<tr class="trConten t">
<td align=left colspan="2"
style="padding-left:5px;">Conf irmation</td>
</tr>
<tr style="height:8 5px;">
<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:LinkButt on CausesValidatio n="false"
id="lnkConfirmY 1" onclick="lnkCon firmY1_Click" runat="server" Text="OK"
CssClass="but_s ub"
OnClientClick=" hideWrap('divWr ap');hideWrap(' divWrapC');" Height="18"
Width="60"></asp:LinkButton>
<asp:LinkButt on CausesValidatio n="false"
id="lnkErrorY1 " onclick="lnkErr orY1_Click" runat="server" Text="OK"
CssClass="but_s ub" OnClientClick=" hideWrap('divWr apC');" Height="18"
Width="60"></asp:LinkButton>
</td>
</tr>
</table>
</div>
<DIV id="delConfirm " class="divConte nt" runat="server"
visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0>
<TR class="trConten t">
<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="lblConfirmD el" runat="server"> </asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:LinkButt on id="DPYes"
runat="server" Text="Yes" CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" showWrap('divWr apC', false);"
onClick="DPYes_ Click"></asp:LinkButton>
&nbsp;<asp:Link Button
id="No" onClick="No_Cli ck" runat="server" Text="No" CssClass="but_s ub"
OnClientClick=" hideWrap('divWr ap');" 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:1 8px;" valign="bottom"
class="texthead ing">Company Setup</td>
</tr>
<tr>
<td style="height:1 px;"
class="dotline" ></td>
</tr>
<tr>
<td style="height:1 0px;"
align="right"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<uc:CompanyTa bs ID="CompanyTabs " runat="server"
/>
</td>
</tr>
</table>
<table id="tableDepart ments" 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:5 px;"></td>
</tr>
<tr>
<td class="textsubh eading">Departm ents
Info</td>
<td align="right">< asp:LinkButton
ID="DPAddNew" runat="server" Text="Add New" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr ap', false);"
OnClick="DPAddN ew_Click"></asp:LinkButton> &nbsp;<asp:Link Button
ID="DPEdit" runat="server" Text="Edit" CssClass="but_s ub" Height="18"
Width="60" OnClientClick=" showWrap('divWr ap',true);"
OnClick="DPEdit _Click"></asp:LinkButton> &nbsp;<asp:Link Button
ID="DPDelete" runat="server" Text="Delete" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr ap',true);"
onClick="DPDele te_Click"></asp:LinkButton> </td>
</tr>
<tr>
<td colspan="2">
<asp:GridView SkinID="List"
ID="DPGridView " runat="server"
DataKeyNames="H DepartmentId,HL ocationId,HComp anyId,HDivision Id,Departmen
tName,Departmen tCode,LocationN ame" OnDataBound="DP GridView_OnData Bound">

<Columns>
<asp:BoundFie ld
HeaderText="Com pany" DataField="Comp anyName" ItemStyle-Width="19%" />
<asp:BoundFie ld
HeaderText="Loc ationName" DataField="Loca tionName" ItemStyle-Width="19%"
/>
<asp:BoundFie ld
HeaderText="Div isionName" DataField="Divi sionName" ItemStyle-Width="19%"
/>
<asp:BoundFie ld
HeaderText="Dep artmentName" DataField="Depa rtmentName"
ItemStyle-Width="24%" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="height:5 px;"></td>
</tr>
</table>
<div id="divDepartme ntsInfo" runat="server"
class="divConte nt" visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0>
<tr class="trConten t">
<td align=left
style="padding-left:5px;">Add/Edit Departments Info</td>
<td align=right>
<asp:LinkButt on id="lnkAClose"
onclick="lnkACl ose_Click" runat="server" Text="X" CssClass=""
CausesValidatio n="False" OnClientClick=" hideWrap('divWr ap');"
ToolTip="Close" ></asp:LinkButton> &nbsp;
</td>
</tr>
<tr>
<td style="height:5 px;"></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:9 px; padding-left:3px;"><asp :ValidationSumm ary
ValidationGroup ="Department s" ID="vsDepartmen ts" runat="server"
HeaderText="Inv alid Values: " DisplayMode="Si ngleParagraph" /></td>
</tr>
<tr>
<td style="height:1 5px;"></td>
</tr>
<tr>
<td style="height:2 2px;"
align="right">S elect Company:&nbsp;</td>
<td><asp:DropDo wnList
id="ddlSelectCo mpany" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" CompanyName" DataValueField= "HCompanyId "
TabIndex="1" AutoPostBack=tr ue
OnSelectedIndex Changed="ddlSel ectCompany_Sele ctedIndexChange d"
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectCo mpany" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectCo mpany" ErrorMessage="C ompany;"
ToolTip="Select Company.">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align=right>Sel ect Location:&nbsp; </td>
<td><asp:DropDo wnList
id="ddlSelectLo cation" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" LocationName" DataValueField= "HLocationI d"
TabIndex="2" AutoPostBack=tr ue
OnSelectedIndex Changed="ddlSel ectLocation_Sel ectedIndexChang ed"
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectLo cation" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectLo cation" ErrorMessage="L ocation;"
ToolTip="Select Location."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align=right>Sel ect Division:&nbsp; </td>
<td><asp:DropDo wnList
id="ddlSelectDi vision" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" DivisionName" DataValueField= "HDivisionI d"
TabIndex="2" AutoPostBack=tr ue
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectDi vision" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectDi vision" ErrorMessage="D ivision;"
ToolTip="Select Division."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align="right">D epartment Name:&nbsp;</td>
<td><asp:TextBo x
ID="txtDepartme ntName" runat="server" CssClass="textb oxmust"
TabIndex="3"></asp:TextBox><as p:RequiredField Validator
ID="rfvtxtDepar tmentName" runat="Server" ValidationGroup ="Department s"
ControlToValida te="txtDepartme ntName" ErrorMessage="D epartment;"
ToolTip="Enter Department."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>

<tr>
<td style="height:2 2px;"
align="right">C ode #:&nbsp;</td>
<td><asp:TextBo x
ID="txtDepartme ntCode" runat="server" CssClass="textb oxmust"
TabIndex="5"></asp:TextBox><as p:RequiredField Validator
ID="rfvDepartme ntCode" runat="server" ValidationGroup ="Department s"
ControlToValida te="txtDepartme ntCode" ErrorMessage="C ode;"
ToolTip="Enter Department Code."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:1 5px;"></td>
</tr>
<tr>
<td colspan=1 ></td>
<td
style="height:2 2px;"><asp:Link Button ValidationGroup ="Department s"
ID="DPInsert" runat="server" Text="Insert" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr apC',true);"
onClick="DPInse rt_Click" TabIndex="9"></asp:LinkButton> <asp:LinkButt on
ValidationGroup ="Department s" ID="DPUpdate" runat="server" Text="Update"
CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" showWrap('divWr apC',true);" onClick="DPUpda te_Click"
TabIndex="9"></asp:LinkButton> &nbsp;<asp:Link Button
CausesValidatio n="false" ID="DPCancel" runat="server" Text="Cancel"
CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" hideWrap('divWr ap');" OnClick="DPCanc el_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 ***
Jun 22 '07 #1
2 9944
On Jun 22, 8:33 am, sree reddy <seenuyer...@gm ail.comwrote:
.cs

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Sql ;
using System.Data.Sql Client;

public partial class CompanyDepartme nts : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{

((LinkButton)Co mpanyTabs.FindC ontrol("LinkBut ton4")).CssClas s =
"tabselecte d";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l10")).CssClas s
= "tabselecte dl";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l11")).CssClas s
= "tabselecte d";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l12")).CssClas s
= "tabselecte dr";

this.BindDPGrid View();

ddlSelectCompan y.DataSource =
PMPro.BusinessC lasses.HRCompan y.SelectAllHRCo mpanyByDescript ion_DataRead
er();
ddlSelectCompan y.DataBind();
ddlSelectCompan y.Items.Insert( 0, new ListItem("--", ""));

ddlSelectDivisi on.DataSource =
PMPro.BusinessC lasses.HRDivisi ons.SelectAllHR DivisionsByDesc ription_Data
Reader();
ddlSelectDivisi on.DataBind();
ddlSelectDivisi on.Items.Insert (0, new ListItem("--", ""));

ddlSelectLocati on.DataSource =
PMPro.BusinessC lasses.HRLocati ons.SelectAllHR LocationByDescr iption_DataR
eader();
ddlSelectLocati on.DataBind();
ddlSelectLocati on.Items.Insert (0, new ListItem("--", ""));

}
}
protected override void Render(HtmlText Writer writer)
{
if (DPGridView.Row s.Count 0)
{
foreach (GridViewRow row in DPGridView.Rows )
{
if (row.RowType == DataControlRowT ype.DataRow)
{
row.Attributes. Add("onclick",
Page.ClientScri pt.GetPostBackE ventReference(D PGridView, "Select$" +
row.RowIndex.To String(), true));
}
}
}

base.Render(wri ter);
}

protected void lnkConfirmY1_Cl ick(object sender, EventArgs e)
{
divConfirm.Visi ble = false;
}

protected void lnkErrorY1_Clic k(object sender, EventArgs e)
{
divConfirm.Visi ble = false;
}

private void ClearControls()
{
txtDepartmentNa me.Text = "";
txtDepartmentCo de.Text = "";
ddlSelectCompan y.ClearSelectio n();
ddlSelectDivisi on.ClearSelecti on();
}

private void BindDPGridView( )
{
//if (Request.QueryS tring["HDepartmen tId"] != null &&
Request.QuerySt ring["HDepartmen tId"].ToString() != "")
//{
DPGridView.Data Source =
PMPro.BusinessC lasses.HRDepart ments.SelectAll HRDepartmentsTy pesByHRDepar
tmentsTypeId_Da taTable();
DPGridView.Data Bind();
DPGridView.Sele ctedIndex = 0;
//}
}
protected void DPGridView_OnDa taBound(object sender, EventArgs e)
{
if (DPGridView.Row s.Count 0)
{
DPEdit.Visible = true;
DPDelete.Visibl e = true;
}
else
{
DPEdit.Visible = false;
DPDelete.Visibl e = false;
}
}

protected void DPAddNew_Click( object sender, EventArgs e)
{
this.ClearContr ols();
divDepartmentsI nfo.Visible = true;
DPInsert.Visibl e = true;
DPUpdate.Visibl e = false;
}
protected void DPEdit_Click(ob ject sender, EventArgs e)
{
if (DPGridView.Sel ectedValue != null)
{
this.FillDPCont rols();
divDepartmentsI nfo.Visible = true;
DPInsert.Visibl e = false;
DPUpdate.Visibl e = true;

}

}
protected void DPDelete_Click( object sender, EventArgs e)
{
if (DPGridView.Sel ectedValue != null)
{
delConfirm.Visi ble = true;
DPYes.Visible = true;
lblConfirmDel.T ext =
string.Format(R esources.Resour ce.MSG_ITEM_DEL ETE_CONFIRMATIO N," "+
"Company / Locations Department : " +
DPGridView.Data Keys[DPGridView.Sele ctedIndex].Values["DepartmentName "].T
oString() + "</b>");
}
}
private void DPConfirmationA ctions(string ErrorMessage, LinkButton
VisibleLink, bool IsSuccess)
{
divConfirm.Visi ble = true;
lnkConfirmY1.Vi sible = false;
lnkErrorY1.Visi ble = false;
VisibleLink.Vis ible = true;
if (IsSuccess)
{
ImgConfirm.Imag eUrl =
"~/App_Themes/Blue/Images/correct.gif";
}
else
{
ImgConfirm.Imag eUrl = "~/App_Themes/Blue/Images/error.gif";
}
lblConfirm.Text = ErrorMessage;
}

protected void DPInsert_Click( object sender, EventArgs e)
{

object HCompanyId = null; if
(ddlSelectCompa ny.SelectedValu e.Length 0) { HCompanyId =
Int32.Parse(ddl SelectCompany.S electedValue); }
object HLocationId = null; if
(ddlSelectLocat ion.SelectedVal ue.Length 0) { HLocationId =
Int32.Parse(ddl SelectLocation. SelectedValue); }
object HDivisionId = null; if
(ddlSelectDivis ion.SelectedVal ue.Length 0) { HDivisionId =
Int32.Parse(ddl SelectDivision. SelectedValue); }
object DepartmentName = null; if
(txtDepartmentN ame.Text.Trim() .Length 0) { DepartmentName =
txtDepartmentNa me.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentC ode.Text.Trim() .Length 0) { DepartmentCode =
txtDepartmentCo de.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessC lasses.HRDepart ments.Insert(HC ompanyId, HLocationId,
HDivisionId, txtDepartmentNa me.Text.Trim(),
txtDepartmentCo de.Text.Trim()) ;

divConfirm.Visi ble = true;

if (RecordStatus == 1)
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_ADD
, "DepartmentName "), lnkConfirmY1, true);
divDepartmentsI nfo.Visible = false;
this.ClearContr ols();
this.BindDPGrid View();

}
if (RecordStatus == 0)
{
lblConfirm.Text =
string.Format(R esources.Resour ce.MSG_ITEM_ALR EADY_EXISTS, "Informatio n",
"Name");

}
}

protected void DPUpdate_Click( object sender, EventArgs e)
{

object DepartmentName = null; if
(txtDepartmentN ame.Text.Trim() .Length 0) { DepartmentName =
txtDepartmentNa me.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentC ode.Text.Trim() .Length 0) { DepartmentCode =
txtDepartmentCo de.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessC lasses.HRDepart ments.Update((I nt32)DPGridView .SelectedVal
ue, Int32.Parse(ddl SelectCompany.S electedValue),
Int32.Parse(ddl SelectLocation. SelectedValue),
Int32.Parse(ddl SelectDivision. SelectedValue),
txtDepartmentNa me.Text.Trim(), txtDepartmentCo de.Text.Trim()) ;

divConfirm.Visi ble = true;

if (RecordStatus == 1)
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_UPD
ATE, "Department "), lnkConfirmY1, true);
divDepartmentsI nfo.Visible = false;
this.ClearContr ols();
this.BindDPGrid View();
}
else
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_ALR
EADY_EXISTS1, txtDepartmentNa me.Text + "Department Information"),
lnkErrorY1, false);
}
}
protected void DPYes_Click(obj ect sender, EventArgs e)
{

PMPro.BusinessC lasses.HRDepart ments.Delete((I nt32)(DPGridVie w.SelectedVa
lue));

divDepartmentsI nfo.Visible = false;
delConfirm.Visi ble = false;

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_DEL
ETE, "DepartmentType s"), lnkConfirmY1, true);

this.BindDPGrid View();
}
protected void No_Click(object sender, EventArgs e)
{
delConfirm.Visi ble = false;
}
protected void lnkAClose_Click (object sender, EventArgs e)
{
divDepartmentsI nfo.Visible = false;
}
protected void DPCancel_Click( object sender, EventArgs e)
{
divDepartmentsI nfo.Visible = false;
}

private void FillDPControls( )
{
if (DPGridView.Sel ectedValue != null)
{
int Index = DPGridView.Sele ctedIndex;

ddlSelectCompan y.SelectedValue =
DPGridView.Data Keys[Index].Values["HCompanyId "].ToString();

ddlSelectLocati on.SelectedValu e =
DPGridView.Data Keys[Index].Values["HLocationI d"].ToString();
ddlSelectDivisi on.SelectedValu e=
DPGridView.Data Keys[Index].Values["HDivisionI d"].ToString();
txtDepartmentNa me.Text=
DPGridView.Data Keys[Index].Values["DepartmentName "].ToString();
txtDepartmentCo de.Text=
DPGridView.Data Keys[Index].Values["DepartmentCode "].ToString();

}

}
protected void ddlSelectCompan y_SelectedIndex Changed(object sender,
EventArgs e)
{

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

if (ddlSelectCompa ny.SelectedValu e != "")
{
ddlSelectLocati on.DataSource =
PMPro.BusinessC lasses.HRPerson Locations.Selec tAllPersonAcces sibleLocatio
nsByPersonId_Da taReader(Int32. Parse(ddlSelect Company.Selecte dValue));
ddlSelectLocati on.DataBind();
ddlSelectLocati on.Items.Insert (0, new ListItem("--", ""));

}
}
protected void ddlSelectLocati on_SelectedInde xChanged(object sender,
EventArgs e)
{

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

if (ddlSelectLocat ion.SelectedVal ue != "")
{
ddlSelectDivisi on.DataSource =
PMPro.BusinessC lasses.HRDivisi ons.SelectAllPe rsonAccessibleD ivisionsByPe
rsonId_DataRead er(Int32.Parse( ddlSelectLocati on.SelectedValu e));
ddlSelectDivisi on.DataBind();
ddlSelectDivisi on.Items.Insert (0, new ListItem("--", ""));

}
}

}

.aspx

<%@ Page Language="C#" MasterPageFile= "~/Master/Sub.master"
AutoEventWireup ="true" CodeFile="Compa nyDepartments.a spx.cs"
Inherits="Compa nyDepartments" Theme="Blue" %>
<%@ Register TagPrefix="uc" TagName=Company Tabs
Src="~/Controls/CompanyTabs.asc x" %>
<asp:Content ID="Content1" ContentPlaceHol derID="CPH1" Runat="Server">
<div id="divWrapC" class="divWrapp erC"></div>
<asp:UpdatePane l ID="GVPanel" runat="server">
<ContentTemplat e>
<DIV id="divConfirm " class="divConfi rm" runat="server"
visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0
width="500px">
<tr class="trConten t">
<td align=left colspan="2"
style="padding-left:5px;">Conf irmation</td>
</tr>
<tr style="height:8 5px;">
<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:LinkButt on CausesValidatio n="false"
id="lnkConfirmY 1" onclick="lnkCon firmY1_Click" runat="server" Text="OK"
CssClass="but_s ub"
OnClientClick=" hideWrap('divWr ap');hideWrap(' divWrapC');" Height="18"
Width="60"></asp:LinkButton>
<asp:LinkButt on CausesValidatio n="false"
id="lnkErrorY1 " onclick="lnkErr orY1_Click" runat="server" Text="OK"
CssClass="but_s ub" OnClientClick=" hideWrap('divWr apC');" Height="18"
Width="60"></asp:LinkButton>
</td>
</tr>
</table>
</div>
<DIV id="delConfirm " class="divConte nt" runat="server"
visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0>
<TR class="trConten t">
<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="lblConfirmD el" runat="server"> </asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:LinkButt on id="DPYes"
runat="server" Text="Yes" CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" showWrap('divWr apC', false);"
onClick="DPYes_ Click"></asp:LinkButton>
&nbsp;<asp:Link Button
id="No" onClick="No_Cli ck" runat="server" Text="No" CssClass="but_s ub"
OnClientClick=" hideWrap('divWr ap');" 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:1 8px;" valign="bottom"
class="texthead ing">Company Setup</td>
</tr>
<tr>
<td style="height:1 px;"
class="dotline" ></td>
</tr>
<tr>
<td style="height:1 0px;"
align="right"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<uc:CompanyTa bs ID="CompanyTabs " runat="server"
/>
</td>
</tr>
</table>
<table id="tableDepart ments" 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:5 px;"></td>
</tr>
<tr>
<td class="textsubh eading">Departm ents
Info</td>
<td align="right">< asp:LinkButton
ID="DPAddNew" runat="server" Text="Add New" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr ap', false);"
OnClick="DPAddN ew_Click"></asp:LinkButton> &nbsp;<asp:Link Button
ID="DPEdit" runat="server" Text="Edit" CssClass="but_s ub" Height="18"
Width="60" OnClientClick=" showWrap('divWr ap',true);"
OnClick="DPEdit _Click"></asp:LinkButton> &nbsp;<asp:Link Button
ID="DPDelete" runat="server" Text="Delete" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr ap',true);"
onClick="DPDele te_Click"></asp:LinkButton> </td>
</tr>
<tr>
<td colspan="2">
<asp:GridView SkinID="List"
ID="DPGridView " runat="server"
DataKeyNames="H DepartmentId,HL ocationId,HComp anyId,HDivision Id,Departmen
tName,Departmen tCode,LocationN ame" OnDataBound="DP GridView_OnData Bound">

<Columns>
<asp:BoundFie ld
HeaderText="Com pany" DataField="Comp anyName" ItemStyle-Width="19%" />
<asp:BoundFie ld
HeaderText="Loc ationName" DataField="Loca tionName" ItemStyle-Width="19%"
/>
<asp:BoundFie ld
HeaderText="Div isionName" DataField="Divi sionName" ItemStyle-Width="19%"
/>
<asp:BoundFie ld
HeaderText="Dep artmentName" DataField="Depa rtmentName"
ItemStyle-Width="24%" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="height:5 px;"></td>
</tr>
</table>
<div id="divDepartme ntsInfo" runat="server"
class="divConte nt" visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0>
<tr class="trConten t">
<td align=left
style="padding-left:5px;">Add/Edit Departments Info</td>
<td align=right>
<asp:LinkButt on id="lnkAClose"
onclick="lnkACl ose_Click" runat="server" Text="X" CssClass=""
CausesValidatio n="False" OnClientClick=" hideWrap('divWr ap');"
ToolTip="Close" ></asp:LinkButton> &nbsp;
</td>
</tr>
<tr>
<td style="height:5 px;"></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:9 px; padding-left:3px;"><asp :ValidationSumm ary
ValidationGroup ="Department s" ID="vsDepartmen ts" runat="server"
HeaderText="Inv alid Values: " DisplayMode="Si ngleParagraph" /></td>
</tr>
<tr>
<td style="height:1 5px;"></td>
</tr>
<tr>
<td style="height:2 2px;"
align="right">S elect Company:&nbsp;</td>
<td><asp:DropDo wnList
id="ddlSelectCo mpany" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" CompanyName" DataValueField= "HCompanyId "
TabIndex="1" AutoPostBack=tr ue
OnSelectedIndex Changed="ddlSel ectCompany_Sele ctedIndexChange d"
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectCo mpany" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectCo mpany" ErrorMessage="C ompany;"
ToolTip="Select Company.">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align=right>Sel ect Location:&nbsp; </td>
<td><asp:DropDo wnList
id="ddlSelectLo cation" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" LocationName" DataValueField= "HLocationI d"
TabIndex="2" AutoPostBack=tr ue
OnSelectedIndex Changed="ddlSel ectLocation_Sel ectedIndexChang ed"
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectLo cation" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectLo cation" ErrorMessage="L ocation;"
ToolTip="Select Location."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align=right>Sel ect Division:&nbsp; </td>
<td><asp:DropDo wnList
id="ddlSelectDi vision" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" DivisionName" DataValueField= "HDivisionI d"
TabIndex="2" AutoPostBack=tr ue
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectDi vision" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectDi vision" ErrorMessage="D ivision;"
ToolTip="Select Division."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align="right">D epartment Name:&nbsp;</td>
<td><asp:TextBo x
ID="txtDepartme ntName" runat="server" CssClass="textb oxmust"
TabIndex="3"></asp:TextBox><as p:RequiredField Validator
ID="rfvtxtDepar tmentName" runat="Server" ValidationGroup ="Department s"
ControlToValida te="txtDepartme ntName" ErrorMessage="D epartment;"
ToolTip="Enter Department."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>

<tr>
<td style="height:2 2px;"
align="right">C ode #:&nbsp;</td>
<td><asp:TextBo x
ID="txtDepartme ntCode" runat="server" CssClass="textb oxmust"
TabIndex="5"></asp:TextBox><as p:RequiredField Validator
ID="rfvDepartme ntCode" runat="server" ValidationGroup ="Department s"
ControlToValida te="txtDepartme ntCode" ErrorMessage="C ode;"
ToolTip="Enter Department Code."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:1 5px;"></td>
</tr>
<tr>
<td colspan=1 ></td>
<td
style="height:2 2px;"><asp:Link Button ValidationGroup ="Department s"
ID="DPInsert" runat="server" Text="Insert" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr apC',true);"
onClick="DPInse rt_Click" TabIndex="9"></asp:LinkButton> <asp:LinkButt on
ValidationGroup ="Department s" ID="DPUpdate" runat="server" Text="Update"
CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" showWrap('divWr apC',true);" onClick="DPUpda te_Click"
TabIndex="9"></asp:LinkButton> &nbsp;<asp:Link Button
CausesValidatio n="false" ID="DPCancel" runat="server" Text="Cancel"
CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" hideWrap('divWr ap');" OnClick="DPCanc el_Click"
TabIndex="10"></asp:LinkButton> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>

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

*** Sent via Developersdexht tp://www.developersd ex.com***
So, what's the problem?

Jun 22 '07 #2
You might want to look at the property AppendDataBound Items in the drop down
list control. You can create a blank (null) or?? entry that will handle
missing items.

hth
David
"sree reddy" <se*********@gm ail.comwrote in message
news:eh******** ******@TK2MSFTN GP04.phx.gbl...
>
cs

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Sql ;
using System.Data.Sql Client;

public partial class CompanyDepartme nts : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{

((LinkButton)Co mpanyTabs.FindC ontrol("LinkBut ton4")).CssClas s =
"tabselecte d";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l10")).CssClas s
= "tabselecte dl";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l11")).CssClas s
= "tabselecte d";
((TableCell)Com panyTabs.FindCo ntrol("TableCel l12")).CssClas s
= "tabselecte dr";

this.BindDPGrid View();

ddlSelectCompan y.DataSource =
PMPro.BusinessC lasses.HRCompan y.SelectAllHRCo mpanyByDescript ion_DataRead
er();
ddlSelectCompan y.DataBind();
ddlSelectCompan y.Items.Insert( 0, new ListItem("--", ""));

ddlSelectDivisi on.DataSource =
PMPro.BusinessC lasses.HRDivisi ons.SelectAllHR DivisionsByDesc ription_Data
Reader();
ddlSelectDivisi on.DataBind();
ddlSelectDivisi on.Items.Insert (0, new ListItem("--", ""));

ddlSelectLocati on.DataSource =
PMPro.BusinessC lasses.HRLocati ons.SelectAllHR LocationByDescr iption_DataR
eader();
ddlSelectLocati on.DataBind();
ddlSelectLocati on.Items.Insert (0, new ListItem("--", ""));
}
}
protected override void Render(HtmlText Writer writer)
{
if (DPGridView.Row s.Count 0)
{
foreach (GridViewRow row in DPGridView.Rows )
{
if (row.RowType == DataControlRowT ype.DataRow)
{
row.Attributes. Add("onclick",
Page.ClientScri pt.GetPostBackE ventReference(D PGridView, "Select$" +
row.RowIndex.To String(), true));
}
}
}

base.Render(wri ter);
}

protected void lnkConfirmY1_Cl ick(object sender, EventArgs e)
{
divConfirm.Visi ble = false;
}
protected void lnkErrorY1_Clic k(object sender, EventArgs e)
{
divConfirm.Visi ble = false;
}
private void ClearControls()
{
txtDepartmentNa me.Text = "";
txtDepartmentCo de.Text = "";
ddlSelectCompan y.ClearSelectio n();
ddlSelectDivisi on.ClearSelecti on();
}

private void BindDPGridView( )
{
//if (Request.QueryS tring["HDepartmen tId"] != null &&
Request.QuerySt ring["HDepartmen tId"].ToString() != "")
//{
DPGridView.Data Source =
PMPro.BusinessC lasses.HRDepart ments.SelectAll HRDepartmentsTy pesByHRDepar
tmentsTypeId_Da taTable();
DPGridView.Data Bind();
DPGridView.Sele ctedIndex = 0;
//}
}
protected void DPGridView_OnDa taBound(object sender, EventArgs e)
{
if (DPGridView.Row s.Count 0)
{
DPEdit.Visible = true;
DPDelete.Visibl e = true;
}
else
{
DPEdit.Visible = false;
DPDelete.Visibl e = false;
}
}

protected void DPAddNew_Click( object sender, EventArgs e)
{
this.ClearContr ols();
divDepartmentsI nfo.Visible = true;
DPInsert.Visibl e = true;
DPUpdate.Visibl e = false;
}
protected void DPEdit_Click(ob ject sender, EventArgs e)
{
if (DPGridView.Sel ectedValue != null)
{
this.FillDPCont rols();
divDepartmentsI nfo.Visible = true;
DPInsert.Visibl e = false;
DPUpdate.Visibl e = true;

}

}
protected void DPDelete_Click( object sender, EventArgs e)
{
if (DPGridView.Sel ectedValue != null)
{
delConfirm.Visi ble = true;
DPYes.Visible = true;
lblConfirmDel.T ext =
string.Format(R esources.Resour ce.MSG_ITEM_DEL ETE_CONFIRMATIO N," "+
"Company / Locations Department : " +
DPGridView.Data Keys[DPGridView.Sele ctedIndex].Values["DepartmentName "].T
oString() + "</b>");
}
}
private void DPConfirmationA ctions(string ErrorMessage, LinkButton
VisibleLink, bool IsSuccess)
{
divConfirm.Visi ble = true;
lnkConfirmY1.Vi sible = false;
lnkErrorY1.Visi ble = false;
VisibleLink.Vis ible = true;
if (IsSuccess)
{
ImgConfirm.Imag eUrl =
"~/App_Themes/Blue/Images/correct.gif";
}
else
{
ImgConfirm.Imag eUrl = "~/App_Themes/Blue/Images/error.gif";
}
lblConfirm.Text = ErrorMessage;
}

protected void DPInsert_Click( object sender, EventArgs e)
{

object HCompanyId = null; if
(ddlSelectCompa ny.SelectedValu e.Length 0) { HCompanyId =
Int32.Parse(ddl SelectCompany.S electedValue); }
object HLocationId = null; if
(ddlSelectLocat ion.SelectedVal ue.Length 0) { HLocationId =
Int32.Parse(ddl SelectLocation. SelectedValue); }
object HDivisionId = null; if
(ddlSelectDivis ion.SelectedVal ue.Length 0) { HDivisionId =
Int32.Parse(ddl SelectDivision. SelectedValue); }
object DepartmentName = null; if
(txtDepartmentN ame.Text.Trim() .Length 0) { DepartmentName =
txtDepartmentNa me.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentC ode.Text.Trim() .Length 0) { DepartmentCode =
txtDepartmentCo de.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessC lasses.HRDepart ments.Insert(HC ompanyId, HLocationId,
HDivisionId, txtDepartmentNa me.Text.Trim(),
txtDepartmentCo de.Text.Trim()) ;

divConfirm.Visi ble = true;
if (RecordStatus == 1)
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_ADD
, "DepartmentName "), lnkConfirmY1, true);
divDepartmentsI nfo.Visible = false;
this.ClearContr ols();
this.BindDPGrid View();

}
if (RecordStatus == 0)
{
lblConfirm.Text =
string.Format(R esources.Resour ce.MSG_ITEM_ALR EADY_EXISTS, "Informatio n",
"Name");

}
}

protected void DPUpdate_Click( object sender, EventArgs e)
{

object DepartmentName = null; if
(txtDepartmentN ame.Text.Trim() .Length 0) { DepartmentName =
txtDepartmentNa me.Text.Trim(); }
object DepartmentCode = null; if
(txtDepartmentC ode.Text.Trim() .Length 0) { DepartmentCode =
txtDepartmentCo de.Text.Trim(); }
Int16 RecordStatus =
PMPro.BusinessC lasses.HRDepart ments.Update((I nt32)DPGridView .SelectedVal
ue, Int32.Parse(ddl SelectCompany.S electedValue),
Int32.Parse(ddl SelectLocation. SelectedValue),
Int32.Parse(ddl SelectDivision. SelectedValue),
txtDepartmentNa me.Text.Trim(), txtDepartmentCo de.Text.Trim()) ;

divConfirm.Visi ble = true;
if (RecordStatus == 1)
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_UPD
ATE, "Department "), lnkConfirmY1, true);
divDepartmentsI nfo.Visible = false;
this.ClearContr ols();
this.BindDPGrid View();
}
else
{

this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_ALR
EADY_EXISTS1, txtDepartmentNa me.Text + "Department Information"),
lnkErrorY1, false);
}
}
protected void DPYes_Click(obj ect sender, EventArgs e)
{

PMPro.BusinessC lasses.HRDepart ments.Delete((I nt32)(DPGridVie w.SelectedVa
lue));

divDepartmentsI nfo.Visible = false;
delConfirm.Visi ble = false;
this.DPConfirma tionActions(str ing.Format(Reso urces.Resource. MSG_ITEM_DEL
ETE, "DepartmentType s"), lnkConfirmY1, true);

this.BindDPGrid View();
}
protected void No_Click(object sender, EventArgs e)
{
delConfirm.Visi ble = false;
}
protected void lnkAClose_Click (object sender, EventArgs e)
{
divDepartmentsI nfo.Visible = false;
}
protected void DPCancel_Click( object sender, EventArgs e)
{
divDepartmentsI nfo.Visible = false;
}

private void FillDPControls( )
{
if (DPGridView.Sel ectedValue != null)
{
int Index = DPGridView.Sele ctedIndex;

ddlSelectCompan y.SelectedValue =
DPGridView.Data Keys[Index].Values["HCompanyId "].ToString();

ddlSelectLocati on.SelectedValu e =
DPGridView.Data Keys[Index].Values["HLocationI d"].ToString();
ddlSelectDivisi on.SelectedValu e=
DPGridView.Data Keys[Index].Values["HDivisionI d"].ToString();
txtDepartmentNa me.Text=
DPGridView.Data Keys[Index].Values["DepartmentName "].ToString();
txtDepartmentCo de.Text=
DPGridView.Data Keys[Index].Values["DepartmentCode "].ToString();

}

}
protected void ddlSelectCompan y_SelectedIndex Changed(object sender,
EventArgs e)
{

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

if (ddlSelectCompa ny.SelectedValu e != "")
{
ddlSelectLocati on.DataSource =
PMPro.BusinessC lasses.HRPerson Locations.Selec tAllPersonAcces sibleLocatio
nsByPersonId_Da taReader(Int32. Parse(ddlSelect Company.Selecte dValue));
ddlSelectLocati on.DataBind();
ddlSelectLocati on.Items.Insert (0, new ListItem("--", ""));

}
}
protected void ddlSelectLocati on_SelectedInde xChanged(object sender,
EventArgs e)
{

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

if (ddlSelectLocat ion.SelectedVal ue != "")
{
ddlSelectDivisi on.DataSource =
PMPro.BusinessC lasses.HRDivisi ons.SelectAllPe rsonAccessibleD ivisionsByPe
rsonId_DataRead er(Int32.Parse( ddlSelectLocati on.SelectedValu e));
ddlSelectDivisi on.DataBind();
ddlSelectDivisi on.Items.Insert (0, new ListItem("--", ""));

}
}
}
aspx

<%@ Page Language="C#" MasterPageFile= "~/Master/Sub.master"
AutoEventWireup ="true" CodeFile="Compa nyDepartments.a spx.cs"
Inherits="Compa nyDepartments" Theme="Blue" %>
<%@ Register TagPrefix="uc" TagName=Company Tabs
Src="~/Controls/CompanyTabs.asc x" %>
<asp:Content ID="Content1" ContentPlaceHol derID="CPH1" Runat="Server">
<div id="divWrapC" class="divWrapp erC"></div>
<asp:UpdatePane l ID="GVPanel" runat="server">
<ContentTemplat e>
<DIV id="divConfirm " class="divConfi rm" runat="server"
visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0
width="500px">
<tr class="trConten t">
<td align=left colspan="2"
style="padding-left:5px;">Conf irmation</td>
</tr>
<tr style="height:8 5px;">
<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:LinkButt on CausesValidatio n="false"
id="lnkConfirmY 1" onclick="lnkCon firmY1_Click" runat="server" Text="OK"
CssClass="but_s ub"
OnClientClick=" hideWrap('divWr ap');hideWrap(' divWrapC');" Height="18"
Width="60"></asp:LinkButton>
<asp:LinkButt on CausesValidatio n="false"
id="lnkErrorY1 " onclick="lnkErr orY1_Click" runat="server" Text="OK"
CssClass="but_s ub" OnClientClick=" hideWrap('divWr apC');" Height="18"
Width="60"></asp:LinkButton>
</td>
</tr>
</table>
</div>
<DIV id="delConfirm " class="divConte nt" runat="server"
visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0>
<TR class="trConten t">
<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="lblConfirmD el" runat="server"> </asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:LinkButt on id="DPYes"
runat="server" Text="Yes" CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" showWrap('divWr apC', false);"
onClick="DPYes_ Click"></asp:LinkButton>
&nbsp;<asp:Link Button
id="No" onClick="No_Cli ck" runat="server" Text="No" CssClass="but_s ub"
OnClientClick=" hideWrap('divWr ap');" 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:1 8px;" valign="bottom"
class="texthead ing">Company Setup</td>
</tr>
<tr>
<td style="height:1 px;"
class="dotline" ></td>
</tr>
<tr>
<td style="height:1 0px;"
align="right"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<uc:CompanyTa bs ID="CompanyTabs " runat="server"
/>
</td>
</tr>
</table>
<table id="tableDepart ments" 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:5 px;"></td>
</tr>
<tr>
<td class="textsubh eading">Departm ents
Info</td>
<td align="right">< asp:LinkButton
ID="DPAddNew" runat="server" Text="Add New" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr ap', false);"
OnClick="DPAddN ew_Click"></asp:LinkButton> &nbsp;<asp:Link Button
ID="DPEdit" runat="server" Text="Edit" CssClass="but_s ub" Height="18"
Width="60" OnClientClick=" showWrap('divWr ap',true);"
OnClick="DPEdit _Click"></asp:LinkButton> &nbsp;<asp:Link Button
ID="DPDelete" runat="server" Text="Delete" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr ap',true);"
onClick="DPDele te_Click"></asp:LinkButton> </td>
</tr>
<tr>
<td colspan="2">
<asp:GridView SkinID="List"
ID="DPGridView " runat="server"
DataKeyNames="H DepartmentId,HL ocationId,HComp anyId,HDivision Id,Departmen
tName,Departmen tCode,LocationN ame" OnDataBound="DP GridView_OnData Bound">

<Columns>
<asp:BoundFie ld
HeaderText="Com pany" DataField="Comp anyName" ItemStyle-Width="19%" />
<asp:BoundFie ld
HeaderText="Loc ationName" DataField="Loca tionName" ItemStyle-Width="19%"
/>
<asp:BoundFie ld
HeaderText="Div isionName" DataField="Divi sionName" ItemStyle-Width="19%"
/>
<asp:BoundFie ld
HeaderText="Dep artmentName" DataField="Depa rtmentName"
ItemStyle-Width="24%" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="height:5 px;"></td>
</tr>
</table>
<div id="divDepartme ntsInfo" runat="server"
class="divConte nt" visible="false" >
<table class="tableCon tent" cellSpacing=0 cellPadding=0>
<tr class="trConten t">
<td align=left
style="padding-left:5px;">Add/Edit Departments Info</td>
<td align=right>
<asp:LinkButt on id="lnkAClose"
onclick="lnkACl ose_Click" runat="server" Text="X" CssClass=""
CausesValidatio n="False" OnClientClick=" hideWrap('divWr ap');"
ToolTip="Close" ></asp:LinkButton> &nbsp;
</td>
</tr>
<tr>
<td style="height:5 px;"></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:9 px; padding-left:3px;"><asp :ValidationSumm ary
ValidationGroup ="Department s" ID="vsDepartmen ts" runat="server"
HeaderText="Inv alid Values: " DisplayMode="Si ngleParagraph" /></td>
</tr>
<tr>
<td style="height:1 5px;"></td>
</tr>
<tr>
<td style="height:2 2px;"
align="right">S elect Company:&nbsp;</td>
<td><asp:DropDo wnList
id="ddlSelectCo mpany" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" CompanyName" DataValueField= "HCompanyId "
TabIndex="1" AutoPostBack=tr ue
OnSelectedIndex Changed="ddlSel ectCompany_Sele ctedIndexChange d"
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectCo mpany" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectCo mpany" ErrorMessage="C ompany;"
ToolTip="Select Company.">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align=right>Sel ect Location:&nbsp; </td>
<td><asp:DropDo wnList
id="ddlSelectLo cation" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" LocationName" DataValueField= "HLocationI d"
TabIndex="2" AutoPostBack=tr ue
OnSelectedIndex Changed="ddlSel ectLocation_Sel ectedIndexChang ed"
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectLo cation" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectLo cation" ErrorMessage="L ocation;"
ToolTip="Select Location."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align=right>Sel ect Division:&nbsp; </td>
<td><asp:DropDo wnList
id="ddlSelectDi vision" runat="server" CssClass="textb oxmust"
Width="115px" DataTextField=" DivisionName" DataValueField= "HDivisionI d"
TabIndex="2" AutoPostBack=tr ue
AppendDataBound Items="True"></asp:DropDownLis t><asp:Required FieldValidat
or ID="rfvSelectDi vision" runat="Server" ValidationGroup ="Department s"
ControlToValida te="ddlSelectDi vision" ErrorMessage="D ivision;"
ToolTip="Select Division."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:2 2px;"
align="right">D epartment Name:&nbsp;</td>
<td><asp:TextBo x
ID="txtDepartme ntName" runat="server" CssClass="textb oxmust"
TabIndex="3"></asp:TextBox><as p:RequiredField Validator
ID="rfvtxtDepar tmentName" runat="Server" ValidationGroup ="Department s"
ControlToValida te="txtDepartme ntName" ErrorMessage="D epartment;"
ToolTip="Enter Department."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>

<tr>
<td style="height:2 2px;"
align="right">C ode #:&nbsp;</td>
<td><asp:TextBo x
ID="txtDepartme ntCode" runat="server" CssClass="textb oxmust"
TabIndex="5"></asp:TextBox><as p:RequiredField Validator
ID="rfvDepartme ntCode" runat="server" ValidationGroup ="Department s"
ControlToValida te="txtDepartme ntCode" ErrorMessage="C ode;"
ToolTip="Enter Department Code."
SetFocusOnError ="True">*</asp:RequiredFie ldValidator></td>
</tr>
<tr>
<td style="height:1 5px;"></td>
</tr>
<tr>
<td colspan=1 ></td>
<td
style="height:2 2px;"><asp:Link Button ValidationGroup ="Department s"
ID="DPInsert" runat="server" Text="Insert" CssClass="but_s ub"
Height="18" Width="60" OnClientClick=" showWrap('divWr apC',true);"
onClick="DPInse rt_Click" TabIndex="9"></asp:LinkButton> <asp:LinkButt on
ValidationGroup ="Department s" ID="DPUpdate" runat="server" Text="Update"
CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" showWrap('divWr apC',true);" onClick="DPUpda te_Click"
TabIndex="9"></asp:LinkButton> &nbsp;<asp:Link Button
CausesValidatio n="false" ID="DPCancel" runat="server" Text="Cancel"
CssClass="but_s ub" Height="18" Width="60"
OnClientClick=" hideWrap('divWr ap');" OnClick="DPCanc el_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 ***

Jun 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6179
by: mg | last post by:
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" In DataGrid1_UpdateCommand, the lin DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest") enables me to work with ddlTest - with, for example, ddlTest.SelectedValu However, in DataGrid1_EditCommand,...
2
3102
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit is performed. How do I force the usercontrol to display the newly assigned date? I don't have this problem if I place the two dropdownlist and the...
0
1588
by: Managed Code | last post by:
Hello, I have a status and definition table. The status table's current status field relates the ID field of the definition table. I am trying to retrieve the definitions that are associated only with the master_id for the status table's current status. After having some trouble databinding I found a solution using a hidden label to save...
11
5789
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
1
7755
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a label and hours, along with an edit linkbutton. When they click on edit, the edit button turns to Update Cancel TimeID stays read Only
1
16830
by: JJ | last post by:
Hi. I am having trouble getting a dropdownlist to work properly in a detailsview: The code is something like: <asp:DetailsView ID="dvwSubscriber" runat="server" AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="objCurrentSubscriber" DefaultMode="Insert" HeaderText="Subscriber Details">
1
2277
by: ken_wilsonii | last post by:
I ran into this problem it ended up being a combination of this that needed to be done. I believe this will work for a bound list to. The whole problem stems from the two-way binding which has caused me several other headaches. My example is derived from binding a DETAILSVIEW to a SQLDATASOURCE. The field is then converted to a template...
1
4915
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over time. The problem is that when an item has been removed from the lookup table, and a user wants to retrieve a record that used the deleted item,...
4
3234
by: garyhumf7 | last post by:
I have placed a dropdown list in the edititemtemplate of a formview control and followed specific MSDN instructions on how to bind the list source to a separate SQL lookup data source but have the formview bound to the main data source. If I set the selecteditem value to bind to the formview control I always get the following error:...
0
7629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7549
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8061
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6183
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1164
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.