Click here to Skip to main content
15,796,333 members
Home / Discussions / ASP.NET
   

ASP.NET

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 23:39
cofounderChris Maunder12-Jul-09 23:39 
QuestionCoding Help Pin
appache0524-Nov-23 19:04
appache0524-Nov-23 19:04 
AnswerRe: Coding Help Pin
Richard MacCutchan24-Nov-23 23:05
mveRichard MacCutchan24-Nov-23 23:05 
AnswerRe: Coding Help Pin
Andre Oosthuizen25-Nov-23 2:24
mveAndre Oosthuizen25-Nov-23 2:24 
AnswerRe: Coding Help Pin
jschell25-Nov-23 8:02
jschell25-Nov-23 8:02 
QuestionWhat should I start reading to get to where I want to go? Pin
DalTXColtsFan21-Nov-23 12:46
DalTXColtsFan21-Nov-23 12:46 
AnswerRe: What should I start reading to get to where I want to go? Pin
Richard MacCutchan21-Nov-23 22:37
mveRichard MacCutchan21-Nov-23 22:37 
QuestionSelectedIndexChanged for DropDown not fired when first item selected Pin
DalTXColtsFan17-Nov-23 8:41
DalTXColtsFan17-Nov-23 8:41 
AnswerRe: SelectedIndexChanged for DropDown not fired when first item selected Pin
Ron Nicholson17-Nov-23 8:57
professionalRon Nicholson17-Nov-23 8:57 
GeneralRe: SelectedIndexChanged for DropDown not fired when first item selected Pin
DalTXColtsFan17-Nov-23 9:03
DalTXColtsFan17-Nov-23 9:03 
GeneralRe: SelectedIndexChanged for DropDown not fired when first item selected Pin
Andre Oosthuizen18-Nov-23 8:27
mveAndre Oosthuizen18-Nov-23 8:27 
Ron is absolutely correct, When the page is loaded for the first time, the 'Page_Load' event is triggered, and the 'ddlCategory_SelectedIndexChanged' event is not fired because the 'AutoPostBack' property is set to True. However, when you select the first item in the dropdown, the page is posted back to the server, and the 'Page_Load' event is triggered again. This causes the selected index to be reset, and the 'ddlCategory_SelectedIndexChanged' event is not fired.

You should only populate the dropdown list during the initial page load and not on subsequent 'postbacks'. You can do this by wrapping your code inside the 'Page_Load' event with a check for '!IsPostBack' -

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Label3.Text = "In Page Load selected index is " + ddlCategory.SelectedIndex.ToString();
        XXXDbSupport objDBSupport = new XXXDbSupport();
        DbCommand objDBCommand = objDBSupport.CreateDbCommand();
        objDBCommand.CommandType = CommandType.Text;
        string sSQL = "select distinct isnull(Category,'(blank)') as ProdCat from xxx_product order by isnull(Category,'(blank)')";
        objDBCommand.CommandText = sSQL;
        DataTable objDBTable = objDBSupport.FillDataTable(objDBCommand);
        if (objDBTable.Rows.Count > 0)
        {
            ddlCategory.DataTextField = "ProdCat";
            ddlCategory.DataValueField = "ProdCat";
            ddlCategory.DataSource = objDBTable;
            ddlCategory.DataBind();
        }
        else
        {
            ddlCategory.Text = "n/a";
        }
    }
}

protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
    Label2.Text = "The selected index changed to " + ddlCategory.SelectedIndex.ToString();
    XXXDbSupport objDBSupport = new XXXDbSupport();
    DbCommand objDBCommand = objDBSupport.CreateDbCommand();
    objDBCommand.CommandType = CommandType.Text;
    string sSQL = "select distinct isnull(SubCategory,'(blank)') as SubCat from xxx_product ";
    if (ddlCategory.Text == "(blank)")
    {
        sSQL = sSQL + "where isnull(Category,'(blank)') = '(blank)' order by isnull(SubCategory,'(blank)')";
    }
    else
    {
        sSQL = sSQL + "where Category = '" + ddlCategory.Text + "' order by isnull(SubCategory,'(blank)')";
    }
    objDBCommand.CommandText = sSQL;
    DataTable objDBTable = objDBSupport.FillDataTable(objDBCommand);
    if (objDBTable.Rows.Count > 0)
    {
        ddlSubcategory.DataTextField = "SubCat";
        ddlSubcategory.DataValueField = "SubCat";
        ddlSubcategory.DataSource = objDBTable;
        ddlSubcategory.DataBind();
    }
    else
    {
        ddlSubcategory.Text = "n/a";
    }
}

SuggestionRe: SelectedIndexChanged for DropDown not fired when first item selected Pin
Richard Deeming19-Nov-23 22:56
mveRichard Deeming19-Nov-23 22:56 
QuestionDumb it down for one who's basically a beginner Pin
DalTXColtsFan15-Nov-23 6:31
DalTXColtsFan15-Nov-23 6:31 
AnswerRe: Dumb it down for one who's basically a beginner Pin
Andre Oosthuizen15-Nov-23 8:25
mveAndre Oosthuizen15-Nov-23 8:25 
GeneralRe: Dumb it down for one who's basically a beginner Pin
DalTXColtsFan15-Nov-23 12:48
DalTXColtsFan15-Nov-23 12:48 
GeneralRe: Dumb it down for one who's basically a beginner Pin
Andre Oosthuizen16-Nov-23 6:36
mveAndre Oosthuizen16-Nov-23 6:36 
Questioncan't build blazor library in azure pipeline Pin
Super Lloyd6-Sep-23 18:08
Super Lloyd6-Sep-23 18:08 
AnswerRe: can't build blazor library in azure pipeline Pin
Super Lloyd6-Sep-23 19:27
Super Lloyd6-Sep-23 19:27 
QuestionBlazor component debugging Pin
Super Lloyd23-Aug-23 15:16
Super Lloyd23-Aug-23 15:16 
AnswerRe: Blazor component debugging Pin
Super Lloyd24-Aug-23 18:27
Super Lloyd24-Aug-23 18:27 
QuestionHTML SELECT CONTROL WITH RUNAT="SERVER Pin
tchia_k30-Jul-23 4:53
professionaltchia_k30-Jul-23 4:53 
AnswerRe: HTML SELECT CONTROL WITH RUNAT="SERVER Pin
Richard Deeming30-Jul-23 23:14
mveRichard Deeming30-Jul-23 23:14 
Question"Context.UserIdentifier" of SignalR is always null when I use CustomAuthenticationStateProvider in Blazor Server App Pin
Alex Wright 202221-Jul-23 4:45
Alex Wright 202221-Jul-23 4:45 
SuggestionRe: "Context.UserIdentifier" of SignalR is always null when I use CustomAuthenticationStateProvider in Blazor Server App Pin
Richard Deeming24-Jul-23 0:17
mveRichard Deeming24-Jul-23 0:17 
QuestionIs is possible to import an excel file with hyperlinks? Pin
samflex16-Jul-23 18:25
samflex16-Jul-23 18:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.