Re: Asp.net Dropdownlist selected index in changed



Hii Tim_Mac
I am trying both options if i am set autopostback=false to third list
then also the selection is changed. when page is get postback. and when
i am set autopostback=true and writting code to selectionchanged for
capturing selected value so third list in this case also value is get
changed.

again i am giving total code to you.



private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

if(!Page.IsPostBack)
{
try
{
BindDistrictList();
BindSDOList();
BindTalukaList();
BindCircleList();
BindVillageList();
BindSectionDropDownlist();
BindSubSectionDropDownlist();
BindSectionLineDropDownlist();

}

catch(Exception ex)
{
Response.Write("<script language=Javascript>alert('"+
ex.Message.ToString()+"');</script>");
}
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.village_Res_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.village_Res_DropDownList_SelectedIndexChanged);
this.go_Button.Click += new
System.EventHandler(this.go_Button_Click);
this.section_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.section_DropDownList_SelectedIndexChanged);
this.subSection_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.subSection_DropDownList_SelectedIndexChanged);
this.sectionLine_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.sectionLine_DropDownList_SelectedIndexChanged);
this.district_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.district_DropDownList_SelectedIndexChanged);
this.SDO_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.SDO_DropDownList_SelectedIndexChanged);
this.circle_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.circle_DropDownList_SelectedIndexChanged);
this.village_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.village_DropDownList_SelectedIndexChanged);
this.search_Button.Click += new
System.EventHandler(this.search_Button_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void BindSectionDropDownlist()
{
DataView dv = new DataView();
dv = objSectionMaster.GetSectionRecForReports();

section_DropDownList.DataTextField="SectionDesc";
section_DropDownList.DataValueField ="sectionId";
section_DropDownList.DataSource=dv;
section_DropDownList.DataBind();
section_DropDownList.Items.Insert(0,new
ListItem("--Select--","--Select--"));


}


private void BindSubSectionDropDownlist()
{
DataView dv = new DataView();
dv = objSectionMaster.GetSubSectionRecReports();
subSection_DropDownList.DataTextField="SectionDesc";
subSection_DropDownList.DataValueField ="sectionId";
subSection_DropDownList.DataSource=dv;
subSection_DropDownList.DataBind();
subSection_DropDownList.Items.Insert(0,new
ListItem("--Select--","--Select--"));


}



private void BindSectionLineDropDownlist()
{

DataView dv = new DataView();
dv = objSectionMaster.GetSectionLineRecReports();
sectionLine_DropDownList.DataTextField="SectionLineDescription";
sectionLine_DropDownList.DataValueField ="SectionLineId";
sectionLine_DropDownList.DataSource= dv;
sectionLine_DropDownList.DataBind();

sectionLine_DropDownList.Items.Insert(0,new
ListItem("--Select--","-1"));


}





private void section_DropDownList_SelectedIndexChanged(object sender,
System.EventArgs e)
{
try
{

DataSet ds = new DataSet();
ds =
objSectionMaster.GetSubSectionRecForReports1(Convert.ToInt32(section_DropDownList.SelectedValue));

subSection_DropDownList.DataTextField="SectionDesc";
subSection_DropDownList.DataValueField ="SectionId";
subSection_DropDownList.DataSource=ds;
subSection_DropDownList.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=javascript> alert('"+
ex.Message.ToString()+"');</script>");
}


}


private void subSection_DropDownList_SelectedIndexChanged(object
sender, System.EventArgs e)
{
try
{
if(subSection_DropDownList.SelectedValue=="--Select--")
{
return;
}

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Convert.ToInt32(subSection_DropDownList.SelectedValue));
sectionLine_DropDownList.DataTextField="SectionLineDescription";
sectionLine_DropDownList.DataValueField ="SectionId";
sectionLine_DropDownList.DataSource=dv;
sectionLine_DropDownList.DataBind();
//resource_Label.Text = sectionLine_DropDownList.SelectedItem.Text;
//sectionLine_DropDownList.Items.Insert(0,new
ListItem("--Select--","--Select--"));
}
catch(Exception ex)
{
Response.Write("<script language=javascript> alert('"+
ex.Message.ToString()+"');</script>");
}
}





Tim_Mac wrote:
hi Santosh,
it is difficult to follow your situation. you say that after you change
List3 that it resets the index back to 0 when the page posts back. am i
right in saying that the postback is because List3 has AutoPostBack=true?
the reason i ask is because you don't appear to have a SelectedIndexChanged
event for List3. so i'm not sure why you would want List3 to post back
itself.

i hope you can clarify the above question. also, please post your aspx code
with the 3 lists, and your InitialiseComponent code to make sure you have
wired the events correctly with the menus.

tim

.


Loading