How to solve the problem that the SelectIndex obtained by DropDownList is always zero
This article focuses on "how to solve the problem that the SelectIndex obtained by DropDownList has always been zero". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to solve the problem that the SelectIndex obtained by DropDownList has always been zero"!
1. If you want DropDownList autocommit, you must set the AutoPostBack= "true" property. Here is the code:
The copy code is as follows:
two。 When processing on the server, especially when initializing DropDownList, do not notice that the result is written incorrectly. The following is the error code:
The copy code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page.IsCallBack)
{
This.fillIntoNameList ()
}
}
There is a mistake in this initialization judgment. It will be initialized every time it is sent to the server, which results in that the SelectIndex of DropDownList can only be 0 each time.
The copy code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page.IsPostBack)
{
This.fillIntoNameList ()
}
}
At this point, I believe you have a deeper understanding of "how to solve the problem that the SelectIndex obtained by DropDownList has always been 0". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!