在我的网页上进行选择并点击“保存”按钮后,我始终会收到"0"
值ListItem
。我希望得到任何选择而不是总是得到同样的东西。
我的代码是从摄像机获取一系列分辨率,并按照正确的顺序将它们放入DropDownList
(ddlResolution
)。
主要代码:
//there is code above but ~should~ be irrelevant
//selectedCam is a custom object. its the video camera
if (selectedCam != null)
{
//this will get an array of resolutions for this camera
string[] res = selectedCam.GetValidResolutionsAsArray();
ddlResolution.ClearSelection();
ddlResolution.Items.Clear();
//putt resolutions in correct order
if (res.Length >= 3)
{
AddItem(ddlResolution, GetResolutionQualityString(1, res), "1");
AddItem(ddlResolution, GetResolutionQualityString(0, res), "0");
//ignore extra small resolutions...thats why we skip "2"
//check to see if the last resolution a duplicate
string hd = string.Format((string)GetLocalResourceObject("ResMedium"), res[3]);
if (res.Length >= 4 && ddlResolution.Items.FindByText(hd) == null)
AddItem(ddlResolution, GetResolutionQualityString(3, res), "3");
}
if (!resolutionSelected) SelectValue("0", ddlResolution);
}
上述代码中使用的方法:
private static void AddItem(DropDownList ddl, string text, string value)
{
ddl.Items.Add(new ListItem(text, value));
}
//gets strings from a resource file
private string GetResolutionQualityString(int i, string[] res)
{
if (res == null || res.Length <= 0) return "";
switch (i)
{
case 0: return string.Format((string)GetLocalResourceObject("ResMedium"), res[i]);
case 1: return string.Format((string)GetLocalResourceObject("ResLow"), res[i]);
case 3: return string.Format((string)GetLocalResourceObject("ResHigh"), res[i]);
default: return "";
}
}
private void SelectValue(string value, ListControl rbList)
{
foreach (ListItem li in rbList.Items)
if (li.Value == value)
li.Selected = true;
}
保存按钮的方法中的代码:
log.Info("ddlResolution.SelectedValue = " + ddlResolution.SelectedValue);//TODO REMOVE
无论我选择什么,都会提供以下内容:
2014年7月2日 17:54:25.049 7812 CLASSNAME信息ddlResolution.SelectedValue = 0
2014年7月2日 17:54:30.844 5556 CLASSNAME信息ddlResolution.SelectedValue = 0
2014年7月2日 17:54:35.008 7504 CLASSNAME信息ddlResolution.SelectedValue = 0