0
간단한 예제처럼 문자열 배열에 바인딩 된 드롭 다운 목록이있는 간단한 양식이 있습니다. 사용자가 단추를 클릭하면 양식이 제출됩니다.ASP 자동 저장 기능이없는 데이터 바인딩 된 드롭 다운 목록
목록에서 선택한 항목을 쿼리하고 싶습니다. 나는 폼에서 선택한 것과 상관없이 항상 기본 항목을 포함하는 드롭 다운 목록의 SelectedValue 멤버를 읽습니다.
프로덕션 환경 에서처럼 autopostback을 사용할 수 없습니다. 양식은 jquery를 사용하여 동적 div에 표시됩니다.
바인딩을 제거하고 ListItems 태그를 사용하여 asp 파일의 목록 항목을 추가하면 마술처럼 작동합니다.
내 샘플 ASP 코드 :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
그리고 코드 숨김 파일 :를 Page_Load에서
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] items = { "bindItem1", "bindItem2", "bindItem3" };
DropDownList1.DataSource = items;
DropDownList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string text = TextBox1.Text;
string item = DropDownList1.SelectedValue;
}
}
감사합니다. 그런 절름발이 실수 ... – hthms