dropdown selected index changed event fires while setting data from database in asp.net c#












0














I have dropdown inside update panel showing some list. When I select dropdown item, selected index changed event fires to populate other dropdown and data is saved and displayed in grid on submit. When I select grid row to edit, dropdown is set with database data. Now all things work fine. But when I select other control with postback, selected index changed event of that dropdown fires without selecting item and resets other dropdown with data to index 0. Why this event fires without selecting dropdown? Please help.



<asp:DropDownList ID="ddl" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="ddl_SelectedIndexChanged">
</asp:DropDownList>

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
Fillddl();
}
public void Fillddl()
{
try
{
DataSet ds_ddl = _BLL.get_AllItems(ddl.SelectedValue);
if (ds_ddl != null)
{
if (ds_ddl .Tables[0].Rows.Count > 0)
{
ddl2.DataSource = ds_ddl.Tables[0].DefaultView;
ddl2.DataTextField = "NAME";
ddl2.DataValueField = "ID";
ddl2.DataBind();
}
}
ddl2.Items.Insert(0, new ListItem("Select", "0"));
ddl2.Dispose();
}
catch { }
}









share|improve this question
























  • Please add your code
    – Just code
    Nov 21 at 4:42










  • are you binding the first ddl in the page load? if yes , have you kept that binding code in Page.IsPostBack check??
    – Gagan Deep
    Nov 21 at 6:17










  • and what is ddl2.Dispose() doing in your code??
    – Gagan Deep
    Nov 21 at 6:18










  • dispose() releases the memory
    – Krupesh03
    Nov 21 at 7:32
















0














I have dropdown inside update panel showing some list. When I select dropdown item, selected index changed event fires to populate other dropdown and data is saved and displayed in grid on submit. When I select grid row to edit, dropdown is set with database data. Now all things work fine. But when I select other control with postback, selected index changed event of that dropdown fires without selecting item and resets other dropdown with data to index 0. Why this event fires without selecting dropdown? Please help.



<asp:DropDownList ID="ddl" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="ddl_SelectedIndexChanged">
</asp:DropDownList>

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
Fillddl();
}
public void Fillddl()
{
try
{
DataSet ds_ddl = _BLL.get_AllItems(ddl.SelectedValue);
if (ds_ddl != null)
{
if (ds_ddl .Tables[0].Rows.Count > 0)
{
ddl2.DataSource = ds_ddl.Tables[0].DefaultView;
ddl2.DataTextField = "NAME";
ddl2.DataValueField = "ID";
ddl2.DataBind();
}
}
ddl2.Items.Insert(0, new ListItem("Select", "0"));
ddl2.Dispose();
}
catch { }
}









share|improve this question
























  • Please add your code
    – Just code
    Nov 21 at 4:42










  • are you binding the first ddl in the page load? if yes , have you kept that binding code in Page.IsPostBack check??
    – Gagan Deep
    Nov 21 at 6:17










  • and what is ddl2.Dispose() doing in your code??
    – Gagan Deep
    Nov 21 at 6:18










  • dispose() releases the memory
    – Krupesh03
    Nov 21 at 7:32














0












0








0







I have dropdown inside update panel showing some list. When I select dropdown item, selected index changed event fires to populate other dropdown and data is saved and displayed in grid on submit. When I select grid row to edit, dropdown is set with database data. Now all things work fine. But when I select other control with postback, selected index changed event of that dropdown fires without selecting item and resets other dropdown with data to index 0. Why this event fires without selecting dropdown? Please help.



<asp:DropDownList ID="ddl" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="ddl_SelectedIndexChanged">
</asp:DropDownList>

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
Fillddl();
}
public void Fillddl()
{
try
{
DataSet ds_ddl = _BLL.get_AllItems(ddl.SelectedValue);
if (ds_ddl != null)
{
if (ds_ddl .Tables[0].Rows.Count > 0)
{
ddl2.DataSource = ds_ddl.Tables[0].DefaultView;
ddl2.DataTextField = "NAME";
ddl2.DataValueField = "ID";
ddl2.DataBind();
}
}
ddl2.Items.Insert(0, new ListItem("Select", "0"));
ddl2.Dispose();
}
catch { }
}









share|improve this question















I have dropdown inside update panel showing some list. When I select dropdown item, selected index changed event fires to populate other dropdown and data is saved and displayed in grid on submit. When I select grid row to edit, dropdown is set with database data. Now all things work fine. But when I select other control with postback, selected index changed event of that dropdown fires without selecting item and resets other dropdown with data to index 0. Why this event fires without selecting dropdown? Please help.



<asp:DropDownList ID="ddl" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="ddl_SelectedIndexChanged">
</asp:DropDownList>

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
Fillddl();
}
public void Fillddl()
{
try
{
DataSet ds_ddl = _BLL.get_AllItems(ddl.SelectedValue);
if (ds_ddl != null)
{
if (ds_ddl .Tables[0].Rows.Count > 0)
{
ddl2.DataSource = ds_ddl.Tables[0].DefaultView;
ddl2.DataTextField = "NAME";
ddl2.DataValueField = "ID";
ddl2.DataBind();
}
}
ddl2.Items.Insert(0, new ListItem("Select", "0"));
ddl2.Dispose();
}
catch { }
}






c# asp.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 5:02

























asked Nov 21 at 4:40









Krupesh03

195




195












  • Please add your code
    – Just code
    Nov 21 at 4:42










  • are you binding the first ddl in the page load? if yes , have you kept that binding code in Page.IsPostBack check??
    – Gagan Deep
    Nov 21 at 6:17










  • and what is ddl2.Dispose() doing in your code??
    – Gagan Deep
    Nov 21 at 6:18










  • dispose() releases the memory
    – Krupesh03
    Nov 21 at 7:32


















  • Please add your code
    – Just code
    Nov 21 at 4:42










  • are you binding the first ddl in the page load? if yes , have you kept that binding code in Page.IsPostBack check??
    – Gagan Deep
    Nov 21 at 6:17










  • and what is ddl2.Dispose() doing in your code??
    – Gagan Deep
    Nov 21 at 6:18










  • dispose() releases the memory
    – Krupesh03
    Nov 21 at 7:32
















Please add your code
– Just code
Nov 21 at 4:42




Please add your code
– Just code
Nov 21 at 4:42












are you binding the first ddl in the page load? if yes , have you kept that binding code in Page.IsPostBack check??
– Gagan Deep
Nov 21 at 6:17




are you binding the first ddl in the page load? if yes , have you kept that binding code in Page.IsPostBack check??
– Gagan Deep
Nov 21 at 6:17












and what is ddl2.Dispose() doing in your code??
– Gagan Deep
Nov 21 at 6:18




and what is ddl2.Dispose() doing in your code??
– Gagan Deep
Nov 21 at 6:18












dispose() releases the memory
– Krupesh03
Nov 21 at 7:32




dispose() releases the memory
– Krupesh03
Nov 21 at 7:32

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405368%2fdropdown-selected-index-changed-event-fires-while-setting-data-from-database-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405368%2fdropdown-selected-index-changed-event-fires-while-setting-data-from-database-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen