0
列表框填充但找不到所選值。它是空值或默認值(第一項)。每當我選擇另一個項目時,它將更改爲空。我做了!ispostback但仍然沒有。在asp.net/c#/sql中使用嚮導。任何幫助表示讚賞。ListBox SelectValue爲null並且selectindex = -1
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;
}
}
你正在執行一個'FindControl'來獲取一個名爲'lstService'的列表到一個變量中,但是你沒有在任何地方使用'lstbox'變量,而是使用'lstService'。什麼是'lstService'?什麼是你正在使用的「嚮導」? –
lstService是listBox的名稱。我正在使用的嚮導是Wizard1。 Wizard2是另一個單獨的嚮導。我相應地更改了當前代碼(如上所示) – Nitrodbz
此外,當我單擊下一個按鈕時,lstService.items.count爲0? – Nitrodbz