在我尝试导出列表中所选项目的过程中,我已经知道某个项目在我的列表中的排序位置,但我无法将该项目位置处的文本放入变量中。
if (CustomerListbox.SelectedIndex > -1)
{
for (int i = 0; i < CustomerListbox.GetSelectedIndices().Count(); i++)
{
SqlConnection sqlConn = Connection.GetConnection();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlConn;
{
ListItem li = new ListItem();
li.Value = Convert.ToString(CustomerListbox.GetSelectedIndices().GetValue(i)); //Determines position within listbox
li.Text = Convert.ToString(CustomerListbox.Items.FindByValue(li.Value));
//^^^some magic line of code to do li.text = Items.somethingselected@position5.Value
sqlCmd.CommandText = "ExportCustomers";
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("myquery", "insert into CustomerSelect(Customers) values('" + li.Text + "')");
}
try
{
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
}
catch (Exception e2)
{
throw e2;
}
sqlConn.Close();
}
}