列表框填充但找不到所选值。它是 null 或默认值(第一项)。每当我选择另一个项目时,它都会变为 null。我做了 !ispostback 但仍然没有。在 asp.net/c#/sql 中使用向导。任何帮助表示赞赏。
protected void Page_Load(object sender, EventArgs e)
{
ListBox lstService = (ListBox)Wizard1.FindControl("lstService");
string s = lstService.SelectedValue.ToString();
int s1 = lstService.SelectedIndex;
if (s == "MarketTrack Toys")
{
Wizard2.Visible = true;
}
if (!Page.IsPostBack)
{
BindGrid();
}
if ((Wizard1.ActiveStepIndex <= 5) && (Wizard1.ActiveStepIndex != 0))
{
Wizard1.DisplaySideBar = true;
Wizard2.DisplaySideBar = false;
}
else
{
Wizard1.DisplaySideBar = false;
Wizard2.DisplaySideBar = true;
}
}
private void BindGrid()
{
dAS = new DataAccessClass();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds = dAS.func_FillDataset("select servicename from dbo.Services", "Services");
ListBox lstService = (ListBox)Wizard1.FindControl("lstService");
lstService.DataSource = ds;
lstService.DataTextField = "ServiceName";
lstService.DataValueField = "ServiceName";
lstService.DataBind();
if (lstService.Items.Count > 0)
{
lstService.SelectedIndex = 0;
}
}