Re: Asp.net Dropdownlist selected index in changed
- From: "Santosh" <Santoshmshinde_it@xxxxxxxxx>
- Date: 11 Sep 2006 21:38:08 -0700
hi Tim_Mac
it is not like that say
if i select fifth item from the third list then after page is post
back it will lose selection from fifth to first item in the list.
Tim_Mac wrote:
hi Santosh,
when you say the index remains the same, do you mean when you change the
index to the 5th item (for example) that it stays on the 5th item after the
SelectedIndexChanged event? or that it stays on the first 'Select...' item
after the event?
tim
"Santosh" <Santoshmshinde_it@xxxxxxxxx> wrote in message
news:1157988048.275498.23380@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dear Tim
The selected index of first two lists remain same but only thirds are
change it change on
change List3 and and click search also.
please help me. what exactely wrong happen.
regards
Santosh
Tim_Mac wrote:
hi Santosh,
your code looks normal. in your original post, you say
"selection index of first two dropdownlist is not changed but
the third selected index of third dropdownlist is changed
when i am click on search button."
i am assuming that you have EnableViewStated = true and AutoPostBack=true
set on all 3 drop down lists, and that the SelectedIndexChanged events
are
correctly registered for all 3 menus, and that these events are firing
correctly.
if this is the case then when you change List1, it will postback and the
selectedIndex of List1 should stay on what you selected. It should also
stay for all future postbacks unless you re-bind the list. Does this
happen?
when you click on the search button, the SelectedIndex of all 3 lists
should
be the same as you left it. from the description of your steps below,
can
you say exactly where your code behaves unexpectedly:
Step 1: change List1
Step 2: change List2
Step 3: change List3
Step 4: click search.
tim
"Santosh" <Santoshmshinde_it@xxxxxxxxx> wrote in message
news:1157796681.766632.104180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Here is code ..
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!Page.IsPostBack)
{
try
{
BindSectionDropDownlist();
BindSubSectionDropDownlist();
BindSectionLineDropDownlist();
}
catch(Exception ex)
{
Response.Write("<script language=Javascript>alert('"+
ex.Message.ToString()+"');</script>");
}
}
}
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();
}
catch(Exception ex)
{
Response.Write("<script language=javascript> alert('"+
ex.Message.ToString()+"');</script>");
}
}
private void search_Button_Click(object sender, System.EventArgs e)
{
SearchCondition();
}
Private void SearchCondition ();
{
Code for Searching according to the selection of third dropdown
list.
}
Regards
Shinde Santosh.
Tim_Mac wrote:
typically this is done via AutoPostBack dropdownlists. it seems
strange
that you bind all 3 lists on the first Page_Load, since you can't know
what
to populate lists 2 and 3 with until a selection has been made with
list
1.
normally i would do something like this (pseudo-code):
First Page_Load (!PostBack) > Bind List 1 (lists 2 and 3 remain
empty)
List1_SelectedIndex_Changed > Bind List 2
List2_SelectedIndex_Changed > Bind List 3
List3_SelectedIndex_Changed > Search whatever
have you got AutoPostBack=true on all the lists? also, you haven't
posted
the SelectedIndexChanged events. it's very difficult to piece
together
your
situation with only a part of the code. if you post all the relevant
code i
will be happy to take a look again.
tim
"Santosh" <Santoshmshinde_it@xxxxxxxxx> wrote in message
news:1157626805.588538.29190@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The description is ,
i am having three dropdownlists when i am selected first item from
list
it will display all related items in the next drop down list when i
am
choose item from second drop down list in third all items filled
related to second item selection. and in the selection of third
dropdown list item text i will be display result.
eg.i am having first dropdownlist it will contains all country list
when i am choose one country it will display all states related to
that
country. if i am selected state from list it will display all
districts
related to the selected states. and on the selection of district i
will
be search another information.
Tim_Mac wrote:
hi,
first it would be useful to describe what you are trying to do.
code
is
helpful but it's no good unless you describe what you are trying to
do
with
it!
you say that the selected index of the first two dropdownlists are
not
changed, are they supposed to change? in response to the user? or
your
code?
you have this line of code in each bind method:
//reportCategoty_DropDownList.SelectedIndex=-1;
is it supposed to be uncommented?
happy to help if you can provide more info
tim
"Santosh" <Santoshmshinde_it@xxxxxxxxx> wrote in message
news:1157365428.171679.43920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dear all ,
i am writting following code.
if(Page.IsPostBack==false)
{
try
{
BindSectionDropDownlist();
BindSubSectionDropDownlist();
BindSectionLineDropDownlist();
}
catch(Exception ex)
{
Response.Write("<script language=Javascript>alert('"+
ex.Message.ToString()+"');</script>");
}
}
}
// Defination of BindSectionDropDownList
private void BindSectionDropDownlist()
{
DataView dv = new DataView();
dv = objSectionMaster.GetSectionRecForReports();
reportCategory_Dropdownlist.DataTextField="SectionDesc";
reportCategory_Dropdownlist.DataValueField ="sectionId";
reportCategory_Dropdownlist.DataSource=dv;
reportCategory_Dropdownlist.DataBind();
reportCategory_Dropdownlist.Items.Insert(0,new
ListItem("--Select--","--Select--"));
//reportCategoty_DropDownList.SelectedIndex=-1;
}
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--"));
//reportCategoty_DropDownList.SelectedIndex=-1;
}
private void BindSectionLineDropDownlist()
{
DataView dv = new DataView();
dv = objSectionMaster.GetSectionLineRecReports();
sectionLineDesc_DropDownList.DataTextField="SectionLineDescription";
sectionLineDesc_DropDownList.DataValueField ="SectionLineId";
sectionLineDesc_DropDownList.DataSource= dv;
sectionLineDesc_DropDownList.DataBind();
sectionLineDesc_DropDownList.Items.Insert(0,new
ListItem("--Select--","-1"));
//reportCategoty_DropDownList.SelectedIndex=-1;
}
private void search_Button_Click(object sender, System.EventArgs
e)
{
selectQuery();
}
selectQuery();
{
//Code for further processing of on the basis of
sectionLineDesc_DropDownList selection
}
selection index of first two dropdownlist is not changed but
the third selected index of third dropdownlist is changed
when i am click on search button.
any help will be greatly appreciated.
.
- Follow-Ups:
- Re: Asp.net Dropdownlist selected index in changed
- From: Tim_Mac
- Re: Asp.net Dropdownlist selected index in changed
- References:
- Asp.net Dropdownlist selected index in changed
- From: Santosh
- Re: Asp.net Dropdownlist selected index in changed
- From: Tim_Mac
- Re: Asp.net Dropdownlist selected index in changed
- From: Santosh
- Re: Asp.net Dropdownlist selected index in changed
- From: Tim_Mac
- Re: Asp.net Dropdownlist selected index in changed
- From: Santosh
- Re: Asp.net Dropdownlist selected index in changed
- From: Tim_Mac
- Re: Asp.net Dropdownlist selected index in changed
- From: Santosh
- Re: Asp.net Dropdownlist selected index in changed
- From: Tim_Mac
- Asp.net Dropdownlist selected index in changed
- Prev by Date: Databinding and hierarchical controls
- Next by Date: Delete a file
- Previous by thread: Re: Asp.net Dropdownlist selected index in changed
- Next by thread: Re: Asp.net Dropdownlist selected index in changed
- Index(es):