By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,967 Members | 843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,967 IT Pros & Developers. It's quick & easy.

Asp.net Dropdownlist selected index in changed

P: n/a
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="Section Desc";
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="Sectio nLineDescription";
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.

Sep 4 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.

Sep 6 '06 #2

P: n/a
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.
Sep 7 '06 #3

P: n/a
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" <Sa***************@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegr oups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.

Sep 8 '06 #4

P: n/a
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="SectionLin eDescription";
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(Conve rt.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=javascriptalert('"+
ex.Message.ToString()+"');</script>");
}

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

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Conv ert.ToInt32(subSection_DropDownList.SelectedValue) );
sectionLine_DropDownList.DataTextField="SectionLin eDescription";
sectionLine_DropDownList.DataValueField ="SectionId";
sectionLine_DropDownList.DataSource=dv;
sectionLine_DropDownList.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=javascriptalert('"+
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" <Sa***************@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.
Sep 9 '06 #5

P: n/a
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" <Sa***************@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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="SectionLin eDescription";
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(Conve rt.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=javascriptalert('"+
ex.Message.ToString()+"');</script>");
}

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

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Conv ert.ToInt32(subSection_DropDownList.SelectedValue) );
sectionLine_DropDownList.DataTextField="SectionLin eDescription";
sectionLine_DropDownList.DataValueField ="SectionId";
sectionLine_DropDownList.DataSource=dv;
sectionLine_DropDownList.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=javascriptalert('"+
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" <Sa***************@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegr oups.com...
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegr oups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.


Sep 11 '06 #6

P: n/a
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" <Sa***************@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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="SectionLin eDescription";
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(Conve rt.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=javascriptalert('"+
ex.Message.ToString()+"');</script>");
}

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

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Conv ert.ToInt32(subSection_DropDownList.SelectedValue) );
sectionLine_DropDownList.DataTextField="SectionLin eDescription";
sectionLine_DropDownList.DataValueField ="SectionId";
sectionLine_DropDownList.DataSource=dv;
sectionLine_DropDownList.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=javascriptalert('"+
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" <Sa***************@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.
Sep 11 '06 #7

P: n/a
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" <Sa***************@yahoo.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
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" <Sa***************@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.com...
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="SectionLin eDescription";
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(Conve rt.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=javascriptalert('"+
ex.Message.ToString()+"');</script>");
}

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

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Conv ert.ToInt32(subSection_DropDownList.SelectedValue) );
sectionLine_DropDownList.DataTextField="SectionLin eDescription";
sectionLine_DropDownList.DataValueField ="SectionId";
sectionLine_DropDownList.DataSource=dv;
sectionLine_DropDownList.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=javascriptalert('"+
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" <Sa***************@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegr oups.com...
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegr oups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.

Sep 11 '06 #8

P: n/a
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" <Sa***************@yahoo.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
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" <Sa***************@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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="SectionLin eDescription";
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(Conve rt.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=javascriptalert('"+
ex.Message.ToString()+"');</script>");
}

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

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Conv ert.ToInt32(subSection_DropDownList.SelectedValue) );
sectionLine_DropDownList.DataTextField="SectionLin eDescription";
sectionLine_DropDownList.DataValueField ="SectionId";
sectionLine_DropDownList.DataSource=dv;
sectionLine_DropDownList.DataBind();

}
catch(Exception ex)
{
Response.Write("<script language=javascriptalert('"+
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" <Sa***************@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
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" <Sa***************@yahoo.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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="Section Desc";
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="Sectio nLineDescription";
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.

Sep 12 '06 #9

P: n/a
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
Sep 12 '06 #10

P: n/a
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_Sele ctedIndexChanged);
this.subSection_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.subSection_DropDownList_S electedIndexChanged);
this.sectionLine_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.sectionLine_DropDownList_ SelectedIndexChanged);
this.district_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.district_DropDownList_Sel ectedIndexChanged);
this.SDO_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.SDO_DropDownList_Selected IndexChanged);
this.circle_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.circle_DropDownList_Selec tedIndexChanged);
this.village_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.village_DropDownList_Sele ctedIndexChanged);
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="SectionLin eDescription";
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(Conve rt.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=javascriptalert('"+
ex.Message.ToString()+"');</script>");
}
}
private void subSection_DropDownList_SelectedIndexChanged(objec t
sender, System.EventArgs e)
{
try
{
if(subSection_DropDownList.SelectedValue=="--Select--")
{
return;
}

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Conv ert.ToInt32(subSection_DropDownList.SelectedValue) );
sectionLine_DropDownList.DataTextField="SectionLin eDescription";
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=javascriptalert('"+
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
Sep 12 '06 #11

P: n/a
hi Santosh,
what i was interested in was the aspx which i don't think you sent yet, but
no matter, i have written a simple reproduction of your scenario which works
correctly. i will leave it up to you to compare what is different in your
own situation.

aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs"
Inherits="TestDdl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD id="Head1">
<title>Untitled Page</title>
</HEAD>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddl1_SelectedIndexChanged" ></asp:DropDownList>
<asp:DropDownList ID="ddl2" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddl2_SelectedIndexChanged" ></asp:DropDownList>
<asp:DropDownList ID="ddl3" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddl3_SelectedIndexChanged" ></asp:DropDownList>&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Search" />
<br>
<br>
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</HTML>

code behind:

using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public class TestDdl : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddl1;
protected System.Web.UI.WebControls.DropDownList ddl2;
protected System.Web.UI.WebControls.DropDownList ddl3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
// bind list 1
this.ddl1.DataSource = GetRandomDataSource();
this.ddl1.DataBind();
this.ddl1.Items.Insert(0, new ListItem("Select...", ""));

// disable the textbox and button until all menus have been selected
this.TextBox1.Enabled = false;
this.Button1.Enabled = false;
}
}
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
// bind list 2
this.ddl2.DataSource = GetRandomDataSource();
this.ddl2.DataBind();
this.ddl2.Items.Insert(0, new ListItem("Select...", ""));
}
protected void ddl2_SelectedIndexChanged(object sender, EventArgs e)
{
// bind list 3
this.ddl3.DataSource = GetRandomDataSource();
this.ddl3.DataBind();
this.ddl3.Items.Insert(0, new ListItem("Select...", ""));
}
protected void ddl3_SelectedIndexChanged(object sender, EventArgs e)
{
// enable textbox + search button
this.TextBox1.Enabled = true;
this.Button1.Enabled = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Text = String.Format("You searched for '{0}' with {1} in list
1, {2} in list 2, and {3} in list 3", this.TextBox1.Text,
this.ddl1.SelectedValue, this.ddl2.SelectedValue, this.ddl3.SelectedValue);
}

#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.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private ArrayList GetRandomDataSource()
{
ArrayList arr = new ArrayList();
Random r = new Random();
for(int i = 0; i < 10; i++)
arr.Add(r.Next(9999));
return arr;
}
}
the most likely explanation is that you have EnableViewState=False on one of
your lists, this is why i wanted to see the aspx.

good luck, and i hope this helps.
tim
"Santosh" <Sa***************@yahoo.comwrote in message
news:11********************@d34g2000cwd.googlegrou ps.com...
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_Sele ctedIndexChanged);
this.subSection_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.subSection_DropDownList_S electedIndexChanged);
this.sectionLine_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.sectionLine_DropDownList_ SelectedIndexChanged);
this.district_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.district_DropDownList_Sel ectedIndexChanged);
this.SDO_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.SDO_DropDownList_Selected IndexChanged);
this.circle_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.circle_DropDownList_Selec tedIndexChanged);
this.village_DropDownList.SelectedIndexChanged += new
System.EventHandler(this.village_DropDownList_Sele ctedIndexChanged);
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="SectionLin eDescription";
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(Conve rt.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=javascriptalert('"+
ex.Message.ToString()+"');</script>");
}
}
private void subSection_DropDownList_SelectedIndexChanged(objec t
sender, System.EventArgs e)
{
try
{
if(subSection_DropDownList.SelectedValue=="--Select--")
{
return;
}

DataView dv = new DataView();
dv =
objSectionMaster.GetSectionLinesRecForReports(Conv ert.ToInt32(subSection_DropDownList.SelectedValue) );
sectionLine_DropDownList.DataTextField="SectionLin eDescription";
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=javascriptalert('"+
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

Sep 14 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.