have asp repeater used to insert data into database
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<div class="form-group" >
<div class="col-sm-2 control-label">
English
</div>
<center> <div class="col-sm-2 control-label">
Other Language
</div>
</center>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="form-group" >
<div class="col-sm-2 control-label"> <%# Eval("EnglishTranslation")%><asp:Label ID="Label1" runat="server" Text=' <%# Eval("StaticTRanslationId")%>' Visible="false"></asp:Label> </div>
<div class="col-sm-10"> <input id="Text1" type="text" class="form-control" runat="server" /></div>
</div>
</ItemTemplate>
</asp:Repeater>
i am using paging and its work good but when go to next or previous page data cleared in input text
i am trying to keep data in view stat but i get error this is my c# code
Type 'HR.tblstaticTranslation' in Assembly 'HR, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
List<tblstaticTranslation> list = new List<tblstaticTranslation>();
ReturnDbForTesEntities db = new ReturnDbForTesEntities();
protected void Page_Load(object sender, EventArgs e)
{
list = db.tblstaticTranslation.Where(p => p.LanguageId == 1).ToList();
if (!IsPostBack)
{
GetItems();
retrivedata();
}
}
public int CurrentPage
{
get
{
//get current page number
object obj = this.ViewState["_CurrentPage"];
if (obj == null)
{
return 0;
}
else
{
return (int)obj;
}
}
set
{
//set in viewstate the current page number
this.ViewState["_CurrentPage"] = value;
}
}
private int GetItems()
{
//create new instance of PagedDataSource
PagedDataSource objPds = new PagedDataSource();
//set number of pages will appear
Ods = list;
objPds.PageSize = 10;
objPds.DataSource = Ods.ToList(); ;
objPds.AllowPaging = true;
int count = objPds.PageCount;
objPds.CurrentPageIndex = CurrentPage;
if (objPds.Count > 0)
{
//dispaly controls if there are pages
btnPrevious.Visible = true;
btnNext.Visible = true;
btnLastRecord.Visible = true;
btnFirstRecord.Visible = true;
lblCurrentPage.Visible = true;
lblCurrentPage.Text = "Page " +
Convert.ToString(CurrentPage + 1) + " of " +
Convert.ToString(objPds.PageCount);
}
else
{
//disable controls if there are no pages
btnPrevious.Visible = false;
btnNext.Visible = false;
btnLastRecord.Visible = false;
btnFirstRecord.Visible = false;
lblCurrentPage.Visible = false;
}
btnPrevious.Enabled = !objPds.IsFirstPage;
btnNext.Enabled = !objPds.IsLastPage;
btnLastRecord.Enabled = !objPds.IsLastPage;
btnFirstRecord.Enabled = !objPds.IsFirstPage;
Repeater1.DataSource = objPds;
Repeater1.DataBind();
//}
return count;
}
public List<tblstaticTranslation> Ods { get; set; }
void getdata()
{
List<tblstaticTranslation> liststatic = new List<tblstaticTranslation>();
tblstaticTranslation tbstatic = new tblstaticTranslation();
foreach (RepeaterItem item in Repeater1.Items)
{
string x = ((Label)item.FindControl("Label1")).Text;
HtmlInputText y = ((HtmlInputText)item.FindControl("Text1"));
if (y.Value .Trim() != string.Empty)
{
tbstatic.StaticTRanslationId = Convert.ToInt32(x);
tbstatic.OtherLanguageTranslation = y.Value ;
if (liststatic.Where(p => p.StaticTRanslationId == tbstatic.StaticTRanslationId).FirstOrDefault() == null)
{
liststatic.Add(tbstatic);
}
else
{
liststatic.Remove(liststatic.Where(p => p.StaticTRanslationId == tbstatic.StaticTRanslationId).FirstOrDefault());
liststatic.Add(tbstatic);
}
tbstatic = new tblstaticTranslation();
}
}
var dt = ConvertToDatatable(liststatic);
ViewState.Add("data", dt);
}
void retrivedata()
{
// List<tblstaticTranslation> data = new List<tblstaticTranslation>();
tblstaticTranslation[] newArrayname = (tblstaticTranslation[])ViewState["data"];
List<tblstaticTranslation> data = new List<tblstaticTranslation>();
if (newArrayname != null)
{
data = new List<tblstaticTranslation>(newArrayname);
}
DataTable dt = (DataTable)ViewState["data"];
DataView dataView = new DataView(dt.Select);
foreach (RepeaterItem items in Repeater1.Items)
{
string x = ((Label)items.FindControl("Label1")).Text;
HtmlInputText y = ((HtmlInputText)items.FindControl("Text1"));
int id = Convert.ToInt32(x);
if (dt.Select("StaticTRanslationId=" + id) != null)
{
y.Value = data.Where(p => p.StaticTRanslationId == id).FirstOrDefault().OtherLanguageTranslation;
}
}
}
public object ObjectControl { get; set; }
protected void btnFirstRecord_Click(object sender, EventArgs e)
{
CurrentPage = 0;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
// retrivedata();
getdata();
}
GetItems();
}
protected void btnLastRecord_Click(object sender, EventArgs e)
{
CurrentPage = GetItems() - 1;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
// retrivedata();
getdata();
}
GetItems();
}
protected void btnPrevious_Click1(object sender, EventArgs e)
{
CurrentPage -= 1;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
// retrivedata();
getdata();
}
GetItems();
}
protected void btnNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
getdata();
// retrivedata();
}
GetItems();
}
When you want to keep some data in ViewState it's must be marked as serializable
If you have declare HR.tblstaticTranslation some where then use the serializable attribute as below
[Serializable()]
class tblstaticTranslation
{
...
}
Related
I am using grid view check box to select all the values in the grid view when i click the check box, but the problem i am facing is it is selecting the only the first page value how ever i have coded to bring all the values in but in design it is not working out
this is the image
i want all the check box to checked in design when i press the all check button.
protected void gvBatch_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Pager)
{
DropDownList ddlcountry1 = (DropDownList)e.Row.FindControl("ddlcountry");
populateLocationValues(ddlcountry1);
{
ArrayList checkboxvalues = (ArrayList)Session["BP_PrdId"];
//string Bp_Id = "";
if (checkboxvalues != null && checkboxvalues.Count > 0)
{
string strBp_Id = ((HiddenField)e.Row.FindControl("hf_ProductLblId")).Value.ToString();
if (checkboxvalues.Contains(strBp_Id))
{
CheckBox myCheckBox = (CheckBox)e.Row.FindControl("chkPLPSltItem");
myCheckBox.Checked = true;
}
}
}
DataSet dsaccess = MenuRestriction();
DataRow dr = null;
string sView = "";
string sEdit = "";
string sInsert = "";
string sDeactive = "";
if (dsaccess.Tables.Count > 0)
{
if (dsaccess.Tables[0].Rows.Count > 0)
{
dr = dsaccess.Tables[0].Rows[0];
sView = dr["MnuRgts_View"].ToString();
sEdit = dr["MnuRgts_Edit"].ToString();
sInsert = dr["MnuRgts_Insert"].ToString();
sDeactive = dr["MnuRgts_DeActivate"].ToString();
if (sInsert == "Y" && sDeactive == "Y")
{
BtnDelete.Visible = true;
imgNew.Visible = true;
}
else
{
BtnDelete.Visible = false;
imgNew.Visible = false;
if (sInsert == "Y")
{
imgNew.Visible = true;
}
if (sDeactive == "Y")
{
BtnDelete.Visible = true;
}
}
}
}
}
}
catch (Exception ex)
{
log.Error("gvBatch_RowDataBound", ex);
}
}
protected void gvBatch_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
RememberOldValues();
gvBatch.PageIndex = e.NewPageIndex;
//RetrieveValues();
BindGrid();
LoadLocation();
//RePopulateValues();
}
private void RememberOldValues()
{
ArrayList checkboxvalues = new ArrayList();
string strBp_Id = "";
foreach (GridViewRow row in gvBatch.Rows)
{
//index = (int)gvBatch.DataKeys[row.RowIndex].Value;
strBp_Id = ((HiddenField)row.FindControl("hf_ProductLblId")).Value.ToString();
bool result = ((CheckBox)row.FindControl("chkPLPSltItem")).Checked;
// Check in the Session
if (Session["BP_PrdId"] != null)
checkboxvalues = (ArrayList)Session["BP_PrdId"];
if (result)
{
if (!checkboxvalues.Contains(strBp_Id))
checkboxvalues.Add(strBp_Id);
}
else
{
if (checkboxvalues.Contains(strBp_Id))
checkboxvalues.Remove(strBp_Id);
}
}
if (checkboxvalues != null && checkboxvalues.Count > 0)
Session["BP_PrdId"] = checkboxvalues;
}
protected void gvBatch_PreRender(object sender, EventArgs e)
{
try
{
if (gvBatch.TopPagerRow != null)
{
((Label)gvBatch.TopPagerRow.FindControl("lbCurrentPage")).Text = (gvBatch.PageIndex + 1).ToString();
((Label)gvBatch.TopPagerRow.FindControl("lbTotalPages")).Text = gvBatch.PageCount.ToString();
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnFirst")).Visible = gvBatch.PageIndex != 0;
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnPrev")).Visible = gvBatch.PageIndex != 0;
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnNext")).Visible = gvBatch.PageCount != (gvBatch.PageIndex + 1);
((LinkButton)gvBatch.TopPagerRow.FindControl("lbtnLast")).Visible = gvBatch.PageCount != (gvBatch.PageIndex + 1);
DropDownList ddlist = (DropDownList)gvBatch.TopPagerRow.FindControl("ddlPageItems");
ddlist.SelectedIndex = ddlist.Items.IndexOf(ddlist.Items.FindByValue(ViewState["DropDownPageItems"].ToString()));
gvBatch.AllowPaging = true;
gvBatch.TopPagerRow.Visible = true;
}
}
catch (Exception ex)
{
}
}
protected void gvBatch_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "EDIT")
{
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
string strAgentName = ((HiddenField)row.FindControl("hf_loginName")).Value.ToString();
if (strAgentName != "")
{
Response.Redirect("CustomerDetails.aspx?Name=" + strAgentName, false);
}
}
}
catch (Exception ex)
{
log.Error("gvAgentRowcommand_AgentSummary", ex);
}
}
You can keep a boolean field in your code and set its value to true whenever the select all is clicked. When loading new pages, you can check that field to automatically display all checked. The same can be done when exporting the grid also.
you can modify and use the following Method
private void selectAllChecksInDAtaGrid()
{
foreach (DataGridViewRow item in myDataGrid.Rows)
{
if (Convert.ToBoolean(item.Cells["Column_Name"].Value) == false)
{
item.Cells["Column_Name"].Value = true;
}
}
}
the 'Column_name' is the name of the checkbox column. if you haven'nt named it yet you can also use the index number .
in your case its 0
private void selectAllChecksInDAtaGrid()
{
foreach (DataGridViewRow item in myDataGrid.Rows)
{
if (Convert.ToBoolean(item.Cells[0].Value) == false)
{
item.Cells[0].Value = true;
}
}
}
You should update (ArrayList)Session["BP_PrdId"] to include all the "Id"s of datasource of gridview. then bind data again.
I have a field named country in Invoice.aspx form. I have the below code.
invoice.aspx
<asp:DropDownList ID="lstCountryy" runat="server" Width="216px" Height="27px" AutoPostback="false">
</asp:DropDownList>
invoice.aspx.cs
lstCountryy.SelectedValue = dtInquiry.Rows[0]["country"].ToString();
Page load:
protected void Page_Load(object sender, EventArgs e)
{
txtTotal.Attributes.Add("readonly", "readonly");
txtvatt.Attributes.Add("readonly", "readonly");//added by chetan
txtDiscount.Attributes.Add("readonly", "readonly");//added by chetan
txtAmountInWords.Attributes.Add("readonly", "readonly");
if (!IsPostBack)
{
loadInvoiceDetails();
//SetAllCountries();//added by chetan
if (lstCountryy.SelectedValue == "U.A.E" || lstCountryy.SelectedValue == "BAHRAIN" || lstCountryy.SelectedValue == "SAUDI ARABIA")
{
txtvat.Text = "";
txtvatt.Text = "";
txtBankCharge.Text = "";
txtDiscount.Text = "";
txtDiscountText.Text = "";
txtTotal.Text = "";
vattr.Style.Add("display", "float");
trdeclaration.Visible = false;
//txtvat.Enabled = true;
}
else
{
txtvat.Text = "";
txtvatt.Text = "";
txtBankCharge.Text = "";
txtDiscount.Text = "";
txtDiscountText.Text = "";
txtTotal.Text = "";
vattr.Style.Add("display", "none");
trdeclaration.Visible = true;
}
}
}
Bind dropdownlist:
protected void SetAllCountries()
{
try
{
string queryStrUserType = "SELECT country_id,country_name FROM crm_countries";
ClassDtBaseConnect clsDtResult = new ClassDtBaseConnect();
DataTable dt = clsDtResult.GetDataTable(queryStrUserType);
lstCountryy.DataSource = dt;
lstCountryy.DataValueField = "country_id";
lstCountryy.DataTextField = "country_name";
lstCountryy.DataBind();
lstCountryy.Items.Insert(0, "--Select--");
}
catch (Exception Ex)
{
}
}
dtInquiry is my Inquiry table in which country field is there and I am fetching the value from inquiry form to invoice form. I am not getting the selected value; it shows blank (""). I don't know what's wrong with that. I am a beginner in C#.
I was not getting the selected value.It should be like this: SetAllCountries Should be first and then loadinvoicedetails.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetAllCountries();
loadInvoiceDetails();
.....
.....
}
}
I'm new to asp.net and needs some help. I have a gridview with paging for every 20 records per page, I have a search button outside the gridview. What I need to do is when I click the search button, the results must be bind to gridview(which is happening now), however when the records are more than the pagesize and I need to go to the next page of the grid, the binding is lost and the binded records are the ones form the page on load event. below is my code sample.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
public void BindData()
{
{
List<EventFile> eventFile = new List<EventFile>();
eventFile = CoMailAssociationDAL.GetUploadFileUnAssigned(0, "", "", "U");
if (gvwAssociation.DataSource == null)
{
gvwAssociation.DataSource = eventFile;
gvwAssociation.DataBind();
}
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
int uFlag = 0;
string uploadFlag = this.ddlUploadDate.SelectedValue;
string fileName = this.txtSearchText.Text;
string uploadDt = this.txtDate.Text;
string status = this.ddlStatus.SelectedValue.ToString();
bt = true;
if (status == "Un-Assigned")
{
status = "U";
}
else if (status == "Assigned")
{
status = "A";
}
else
{
status = "B";
}
if ((uploadFlag == "On") && (uploadDt == ""))
{
uFlag = 0;
}
else if (uploadFlag == "On")
{
uFlag = 1;
}
else if (uploadFlag == "OnorBefore")
{
uFlag = 2;
}
else
{
uFlag = 3;
}
fileSearch = CoMailAssociationDAL.SearchFile(uFlag, fileName, uploadDt, status);
gvwAssociation.DataSource = fileSearch;
gvwAssociation.DataBind();
}
protected void gvwAssociation_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//SaveSelectedValues();
gvwAssociation.PageIndex = e.NewPageIndex;
//BindData();
//PopulateSelectedValues();
}
First of all you should have the following event handler for paging
protected void gvwAssociation_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwAssociation.PageIndex = e.NewPageIndex;
bindGridWithFilter();
}
Then, move your search/ filter logic within the search button to a private method (say "bindGridWithFilter")
TIP: Try to combine both BindData and bindGridWithFilter so when there's no filter you display all records
UPDATE
Here's some refactored code for you to get an idea what I meant above.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridWithFilter();
}
}
protected void gvwAssociation_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwAssociation.PageIndex = e.NewPageIndex;
bindGridWithFilter();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
bindGridWithFilter();
}
private void bindGridWithFilter()
{
List<EventFile> eventFile = new List<EventFile>();
eventFile = CoMailAssociationDAL.GetUploadFileUnAssigned(0, "", "", "U");
if (gvwAssociation.DataSource == null)
{
// If you don't have a filter you show all records
gvwAssociation.DataSource = eventFile;
gvwAssociation.DataBind();
}
else
{
// This is same as the logic in your search button
// display only the filtered records
int uFlag = 0;
string uploadFlag = this.ddlUploadDate.SelectedValue;
string fileName = this.txtSearchText.Text;
string uploadDt = this.txtDate.Text;
string status = this.ddlStatus.SelectedValue.ToString();
bt = true;
if (status == "Un-Assigned")
{
status = "U";
}
else if (status == "Assigned")
{
status = "A";
}
else
{
status = "B";
}
if ((uploadFlag == "On") && (uploadDt == ""))
{
uFlag = 0;
}
else if (uploadFlag == "On")
{
uFlag = 1;
}
else if (uploadFlag == "OnorBefore")
{
uFlag = 2;
}
else
{
uFlag = 3;
}
List<EventFile> fileSearch = CoMailAssociationDAL.SearchFile(uFlag, fileName, uploadDt, status);
gvwAssociation.DataSource = fileSearch;
gvwAssociation.DataBind();
}
}
This should work.
ASP.Net code:
<asp:DropDownList ID="ddlKid" runat="server" AutoPostBack="true" CssClass="ddlReports"
Width="160px" OnSelectedIndexChanged="ddlKid_SelectedIndexChanged">
</asp:DropDownList>
C# code:
protected void ddlKid_SelectedIndexChanged(object sender, EventArgs e)
{
int i = ddlKid.SelectedIndex;
count = i;
int KidId = int.Parse(KidArray[i].ToString());
ArrayList ADA = new ArrayList();
ADA.Add(FirstAssignment.SelectedItem);
ADA.Add(SecondAssignment.SelectedItem);
DrawTableNew(ADA, KidId);
}
protected void Page_Load(object sender, EventArgs e)
{
GameLib.Reports.ReportID = 6;
if (!IsPostBack)
{
FillGrades();
FillKids();
count = 0;
Label1.Visible = false;
FirstAssignment.Visible = false;
SecondAssignment.Visible = false;
L1st.Visible = false;
L2nd.Visible = false;
Header.Visible = false;
Label2.Visible = false;
Div2.Visible = false;
Panel1.Visible = false;
DwdTable.Visible = false;
DwdButton2.Visible = false;
pnlIssues.Visible = false;
Panel2.Visible = false;
}
else
{
FillGrades();
// FillKids();
}
}
protected void FillKids()
{
ddlKid.Visible = true;
try
{
if (GameUser.UserType == 1)
{
ddlKid.Items.Insert(0, new System.Web.UI.WebControls.ListItem(GameUser.UserName, GameUser.UserID.ToString()));
}
else
{
DataTable dt = new DataTable();
//dt = GameLib.GameUser.GetKidsForParent(GameUser.UserID);
dt = GameLib.GameUser.GetKidsForParentAsPerGrade(GameUser.UserID, ddlAssessment.SelectedItem.ToString());
for (int i = 0; i < dt.Rows.Count; i++)
{
int kidId = (int)dt.Rows[i]["intUserID"];
KidArray.Add(kidId);
}
if (dt.Rows.Count <= 0)
{
//MPEGrade.Show();
}
else
{
ddlKid.DataSource = dt;
ddlKid.DataTextField = "vchLoginName";
ddlKid.DataValueField = "vchGradeName";
ddlKid.DataBind();
}
}
}
catch
{
}
}
The problem is my ddlKid_SelectedIndexChanged is not executing. After page load it stops at else statement. Its code for fill kids(Adding drop down data).
The fill kid only called on the first that is !postback.
you can change binding value:
fill kids value like:
string vchLoginName=//login name from db;
string vchGradeName=//Grade name from db;
ddlKid.Items.Add(new ListItem(vchLoginName,vchGradeName));
I have a 3 dropdownlist control with a selectedindexchanged event that fires correctly. However, when you select an item from the list the index value that is returned to the selectedindexchanged event does not change; the list box pops back to the first item in the list. Any help would be appreciated. ~Dharmendra~
`public partial class Production : System.Web.UI.Page
{
EmployeeQuotientCL.Production _production = null;
DataSet dsNatureOfWork = new DataSet();
DataSet dsProjectRegion = new DataSet();
DataSet dsCountyDetails = new DataSet();
DataSet dsWorkType = new DataSet();
DataSet dsTask = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string userEcode=Convert.ToString(Session["UserID"]);
_production = new EmployeeQuotientCL.Production();
dsNatureOfWork = _production.GetNatureOfWork();
if (dsNatureOfWork.Tables[0].Rows.Count > 0)
{
BindDdlNatureOfWork(dsNatureOfWork);
}
else
{
}
}
}
public void BindDdlNatureOfWork(DataSet dsNatureOfWork)
{
ddlNatureofWork.DataSource = dsNatureOfWork.Tables[0];
ddlNatureofWork.DataTextField = "NatureOfWorkName";
ddlNatureofWork.DataValueField = "NatureOfWorkID";
ddlNatureofWork.DataBind();
ddlNatureofWork.Items.Insert(0, "--Select Nature of Work--");
}
public void FillRegionProject(int NatureOfWorkID)
{
if ((NatureOfWorkID != null) || (NatureOfWorkID != 0))
{
_production = new EmployeeQuotientCL.Production();
dsProjectRegion = _production.GetProjectRegion(NatureOfWorkID);
if (dsProjectRegion.Tables[0].Rows.Count > 0)
{
ddlRegionProjectName.DataSource = dsProjectRegion.Tables[0];
ddlRegionProjectName.DataTextField = "RegionProjectName";
ddlRegionProjectName.DataValueField = "RegionProjectID";
ddlRegionProjectName.DataBind();
ddlRegionProjectName.Items.Insert(0, "--Select Region/Project--");
}
else
{
}
}
}
protected void ddlRegionProjectName_SelectedIndexChanged(object sender, EventArgs e)
{
int RegionProjectID = Convert.ToInt32(ddlRegionProjectName.SelectedValue.ToString());
FillCounty(RegionProjectID);
ddlRegionProjectName.SelectedIndex = 0;
}
public void FillCounty(int regionprojectID)
{
if ((regionprojectID != null) || (regionprojectID != 0))
{
_production = new EmployeeQuotientCL.Production();
dsCountyDetails = _production.GetCounty(regionprojectID);
if (dsCountyDetails.Tables[0].Rows.Count > 0)
{
ddlCountyName.DataSource = dsCountyDetails.Tables[0];
ddlCountyName.DataTextField = "CountyName";
ddlCountyName.DataValueField = "CountyID";
ddlCountyName.DataBind();
ddlCountyName.Items.Insert(0, "--Select County--");
}
else
{
}
}
}
protected void ddlNatureofWork_SelectedIndexChanged(object sender, EventArgs e)
{
int NowID = Convert.ToInt32(ddlNatureofWork.SelectedValue.ToString());
FillRegionProject(NowID);
ddlRegionProjectName.SelectedIndex = 0;
}
}
}`
You are doing ddlRegionProjectName.SelectedIndex = 0; in every SelectedIndexChanged event.
You have no event for ddlCountyName control in the code shared by you.