powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / DropDownList не сохраняет выбранное значение
2 сообщений из 2, страница 1 из 1
DropDownList не сохраняет выбранное значение
    #33528504
Guest594
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Доброго времени суток!
Вопрос в теме. Код:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
<%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false" Inherits="Documents.Test" EnableViewState="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
		<title>Test</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  </HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<asp:DropDownList id="listLookIn" runat="server" EnableViewState="True"></asp:DropDownList>
<asp:Button id=Button1 runat="server" Text="Button"></asp:Button>
<asp:Literal id=listValue runat="server"></asp:Literal>
		</form>
	</body>
</HTML>

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Documents
{
	/// <summary>
	/// Summary description for Test.
	/// </summary>
	public class Test : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Literal listValue;
		protected System.Web.UI.WebControls.DropDownList listLookIn;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if(!IsPostBack)
			{
					listLookIn.DataSource = CreateDataSource();
					listLookIn.DataTextField = "Name";
					listLookIn.DataValueField = "Path";

					listLookIn.DataBind();
					listLookIn.SelectedIndex =  0 ;
			}
		}

		protected ICollection CreateDataSource() 
		{
			// Create a table to store data for the DropDownList control.
			DataTable dt = new DataTable();
         
			// Define the columns of the table.
			dt.Columns.Add(new DataColumn("Name", typeof(String)));
			dt.Columns.Add(new DataColumn("Path", typeof(String)));

			dt.Rows.Add(CreateRow("Entire Library", String.Empty, dt));
 
			FileSystemObjectCollection coll = listLookInFolder() as FileSystemObjectCollection;
			if (coll != null )
			{
				foreach( FileSystemObject directory in coll )
				{
					dt.Rows.Add(CreateRow(directory.Name, directory.Path, dt));
				}
			}
			// Create a DataView from the DataTable to act as the data source
			// for the DropDownList control.
			DataView dv = new DataView(dt);
			return dv;

		}
		private DataRow CreateRow(String Text, String Value, DataTable dt)
		{
			DataRow dr = dt.NewRow();
			dr[ 0 ] = Text;
			dr[ 1 ] = Value;
			return dr;
		}

		private ICollection	listLookInFolder()
		{
			string rootFolder = Application["LibraryPath"] as string;
			FileSystemManager manager = new FileSystemManager(rootFolder);
			return manager.GetDirectories(string.Empty);
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			this.listValue.Text = this.listLookIn.SelectedItem.Value;
		}

		private void listLookIn_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.listValue.Text = this.listLookIn.SelectedItem.Value;
		}
	}
}

Заранее спасибо!
...
Рейтинг: 0 / 0
DropDownList не сохраняет выбранное значение
    #33528684
Guest594
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Простите,

вопрос снят. Добавлял в лист пустые значения. :))
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / DropDownList не сохраняет выбранное значение
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]