62,072
社区成员
发帖
与我相关
我的任务
分享
<select id="test" runat="server">
<option value="1">测试</option>
<option value="1">测试</option>
<option value="1">测试</option>
<option value="1">测试</option>
</select>
SelectedIndex
获取到的值永远等于0,换用DropDownList,同样。不晓得为什么会这样?bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
{
return this.LoadPostData(postDataKey, postCollection);
}
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string[] values = postCollection.GetValues(postDataKey);
bool flag = false;
if (values != null)
{
if (!this.Multiple)
{
int num = this.Items.FindByValueInternal(values[0], false);
if (this.SelectedIndex != num)
{
this.SelectedIndex = num;
flag = true;
}
}
else
{
int num2 = values.Length;
int[] selectedIndices = this.SelectedIndices;
int[] array = new int[num2];
for (int i = 0; i < num2; i++)
{
array[i] = this.Items.FindByValueInternal(values[i], false);
}
if (selectedIndices.Length == num2)
{
for (int j = 0; j < num2; j++)
{
if (array[j] != selectedIndices[j])
{
flag = true;
break;
}
}
}
else
{
flag = true;
}
if (flag)
{
this.Select(array);
}
}
}
else
{
if (this.SelectedIndex != -1)
{
this.SelectedIndex = -1;
flag = true;
}
}
if (flag)
{
base.ValidateEvent(postDataKey);
}
return flag;
}
public virtual int SelectedIndex
{
get
{
for (int i = 0; i < this.Items.Count; i++)
{
if (this.Items[i].Selected)
{
return i;
}
}
if (this.Size <= 1 && !this.Multiple)
{
if (this.Items.Count > 0)
{
this.Items[0].Selected = true;
}
return 0;
}
return -1;
}
set
{
if (this.Items.Count == 0)
{
this.cachedSelectedIndex = value;
return;
}
if (value < -1 || value >= this.Items.Count)
{
throw new ArgumentOutOfRangeException("value");
}
this.ClearSelection();
if (value >= 0)
{
this.Items[value].Selected = true;
}
}
}
internal int FindByValueInternal(string value, bool includeDisabled)
{
int num = 0;
foreach (ListItem listItem in this.listItems)
{
if (listItem.Value.Equals(value) && (includeDisabled || listItem.Enabled))
{
return num;
}
num++;
}
return -1;
}