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

Discussion in 'ASP .Net' started by sree reddy, Jun 22, 2007.

  1. sree reddy

    sree reddy Guest

    ..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.SelectAllHRCompanyByDescription_DataRead
    er();
    ddlSelectCompany.DataBind();
    ddlSelectCompany.Items.Insert(0, new ListItem("--", ""));

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

    ddlSelectLocation.DataSource =
    PMPro.BusinessClasses.HRLocations.SelectAllHRLocationByDescription_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(DPGridView, "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.SelectAllHRDepartmentsTypesByHRDepar
    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_CONFIRMATION," "+
    "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(HCompanyId, 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.SelectAllPersonAccessibleLocatio
    nsByPersonId_DataReader(Int32.Parse(ddlSelectCompany.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.SelectAllPersonAccessibleDivisionsByPe
    rsonId_DataReader(Int32.Parse(ddlSelectLocation.SelectedValue));
    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('divWrapC');" 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><asp:DropDownList
    id="ddlSelectCompany" runat="server" CssClass="textboxmust"
    Width="115px" DataTextField="CompanyName" DataValueField="HCompanyId"
    TabIndex="1" AutoPostBack=true
    OnSelectedIndexChanged="ddlSelectCompany_SelectedIndexChanged"
    AppendDataBoundItems="True"></asp:DropDownList><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><asp:DropDownList
    id="ddlSelectLocation" runat="server" CssClass="textboxmust"
    Width="115px" DataTextField="LocationName" DataValueField="HLocationId"
    TabIndex="2" AutoPostBack=true
    OnSelectedIndexChanged="ddlSelectLocation_SelectedIndexChanged"
    AppendDataBoundItems="True"></asp:DropDownList><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><asp:DropDownList
    id="ddlSelectDivision" runat="server" CssClass="textboxmust"
    Width="115px" DataTextField="DivisionName" DataValueField="HDivisionId"
    TabIndex="2" AutoPostBack=true
    AppendDataBoundItems="True"></asp:DropDownList><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 ***
     
    sree reddy, Jun 22, 2007
    #1
    1. Advertising

  2. On Jun 22, 8:33 am, sree reddy <> 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.SelectAllHRCompanyByDescription_DataRead
    > er();
    > ddlSelectCompany.DataBind();
    > ddlSelectCompany.Items.Insert(0, new ListItem("--", ""));
    >
    > ddlSelectDivision.DataSource =
    > PMPro.BusinessClasses.HRDivisions.SelectAllHRDivisionsByDescription_Data
    > Reader();
    > ddlSelectDivision.DataBind();
    > ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
    >
    > ddlSelectLocation.DataSource =
    > PMPro.BusinessClasses.HRLocations.SelectAllHRLocationByDescription_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(DPGridView, "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.SelectAllHRDepartmentsTypesByHRDepar
    > 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_CONFIRMATION," "+
    > "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(HCompanyId, 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.SelectAllPersonAccessibleLocatio
    > nsByPersonId_DataReader(Int32.Parse(ddlSelectCompany.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.SelectAllPersonAccessibleDivisionsByPe
    > rsonId_DataReader(Int32.Parse(ddlSelectLocation.SelectedValue));
    > 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('divWrapC');" 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><asp:DropDownList
    > id="ddlSelectCompany" runat="server" CssClass="textboxmust"
    > Width="115px" DataTextField="CompanyName" DataValueField="HCompanyId"
    > TabIndex="1" AutoPostBack=true
    > OnSelectedIndexChanged="ddlSelectCompany_SelectedIndexChanged"
    > AppendDataBoundItems="True"></asp:DropDownList><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><asp:DropDownList
    > id="ddlSelectLocation" runat="server" CssClass="textboxmust"
    > Width="115px" DataTextField="LocationName" DataValueField="HLocationId"
    > TabIndex="2" AutoPostBack=true
    > OnSelectedIndexChanged="ddlSelectLocation_SelectedIndexChanged"
    > AppendDataBoundItems="True"></asp:DropDownList><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><asp:DropDownList
    > id="ddlSelectDivision" runat="server" CssClass="textboxmust"
    > Width="115px" DataTextField="DivisionName" DataValueField="HDivisionId"
    > TabIndex="2" AutoPostBack=true
    > AppendDataBoundItems="True"></asp:DropDownList><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?
     
    Alexey Smirnov, Jun 22, 2007
    #2
    1. Advertising

  3. sree reddy

    David C Guest

    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" <> wrote in message
    news:...
    >
    > 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.SelectAllHRCompanyByDescription_DataRead
    > er();
    > ddlSelectCompany.DataBind();
    > ddlSelectCompany.Items.Insert(0, new ListItem("--", ""));
    >
    > ddlSelectDivision.DataSource =
    > PMPro.BusinessClasses.HRDivisions.SelectAllHRDivisionsByDescription_Data
    > Reader();
    > ddlSelectDivision.DataBind();
    > ddlSelectDivision.Items.Insert(0, new ListItem("--", ""));
    >
    > ddlSelectLocation.DataSource =
    > PMPro.BusinessClasses.HRLocations.SelectAllHRLocationByDescription_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(DPGridView, "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.SelectAllHRDepartmentsTypesByHRDepar
    > 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_CONFIRMATION," "+
    > "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(HCompanyId, 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.SelectAllPersonAccessibleLocatio
    > nsByPersonId_DataReader(Int32.Parse(ddlSelectCompany.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.SelectAllPersonAccessibleDivisionsByPe
    > rsonId_DataReader(Int32.Parse(ddlSelectLocation.SelectedValue));
    > 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('divWrapC');" 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><asp:DropDownList
    > id="ddlSelectCompany" runat="server" CssClass="textboxmust"
    > Width="115px" DataTextField="CompanyName" DataValueField="HCompanyId"
    > TabIndex="1" AutoPostBack=true
    > OnSelectedIndexChanged="ddlSelectCompany_SelectedIndexChanged"
    > AppendDataBoundItems="True"></asp:DropDownList><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><asp:DropDownList
    > id="ddlSelectLocation" runat="server" CssClass="textboxmust"
    > Width="115px" DataTextField="LocationName" DataValueField="HLocationId"
    > TabIndex="2" AutoPostBack=true
    > OnSelectedIndexChanged="ddlSelectLocation_SelectedIndexChanged"
    > AppendDataBoundItems="True"></asp:DropDownList><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><asp:DropDownList
    > id="ddlSelectDivision" runat="server" CssClass="textboxmust"
    > Width="115px" DataTextField="DivisionName" DataValueField="HDivisionId"
    > TabIndex="2" AutoPostBack=true
    > AppendDataBoundItems="True"></asp:DropDownList><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 ***
     
    David C, Jun 22, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page