ListBox在绑定时只有TextField和ValueField,
我现在绑定了两个以上的字段【1】【2】【3】令TextField=【1】,ValueField=【2】
现有三个标签:Label1,2,3  
把TextField的值赋给Label1,而Label2需要根据ValueField的值作为判断条件去赋值问题是Label3需要以字段【3】的值为条件去赋值,而怎样获得【3】的值呢?ListBox只提供TEXTField和ValueField啊
并且这个问题好像不是合并字段能解决的,我需要的仅仅是【3】单独的值。哪位高人有好的见解请赐教。

解决方案 »

  1.   

    根据【2】的值找到【2】在table中的行dr,Label3=dr[【3】]
      

  2.   

    这个怎么与table有关系呢 是ListBox啊
      

  3.   

    1楼的意思是得到[2]后,从listbox的数据源中找到对应的[3],你绑定listbox总会先有个数据源吧
      

  4.   

    手动给ListBox添加项,然后给每一项即ListItem添加属性。这个属性值就是你说的【3】,然后在客户端读取指定的属性。
    namespace testWebForm
    {
        public struct person
        {
            private string _name;        public string Name
            {
                get { return _name; }
                set { _name = value; }
            }        private int _age;        public int Age
            {
                get { return _age; }
                set { _age = value; }
            }        private string _jobTitle;        public string JobTitle
            {
                get { return _jobTitle; }
                set { _jobTitle = value; }
            }        public person(string name, int age, string jobTitle)
            {
                this._name = name;
                this._age = age;
                this._jobTitle = jobTitle;
            }    }    public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    List<person> collection = new List<person>();
                    ListItem item = null;
                    collection.Add(new person("name1",1,"asp.net"));
                    collection.Add(new person("name2",2,"js"));
                    for (int i = 0; i < collection.Count; i++)
                    {
                        item = new ListItem(collection[i].Name,collection[i].Age.ToString());
                        item.Attributes.Add("title", collection[i].JobTitle);
                        ls.Items.Add(item);
                    }
                }
            }
        }
    }
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
        <script type="text/javascript">        function clickHandler()
            {
                var ls = document.getElementById("ls");
                if (ls.selectedIndex > -1)
                {
                    window.alert(ls.options[ls.selectedIndex].title);
                }
                
            }
            
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         <asp:ListBox ID="ls" runat="server">
         
         </asp:ListBox>
        <input type="button" onclick="clickHandler()" value="test" />
        </div>
        </form>
    </body>
    </html>
      

  5.   

    我的数据源是确定的 数据表中有[Category],[DefaultValue] ,[EvalType]等字段 如下绑定的:
    <asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Category" DataValueField="EvalType" Height="260px" Width="426px" BackColor="#e6e6fa"></asp:ListBox>
               <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EvaluationConnectionString %>" SelectCommand="SELECT [Category],[DefaultValue] ,[EvalType] FROM [Rules4PM] where ItemID like '0202010%'"></asp:SqlDataSource>能通过js代码获取TextField 和ValueField的值将其赋给相应标签,
    问题是怎样单独获取第三个值EvalType(int型),我要以它的值为条件进行后面的操作。
    不知我说清楚没有,还请高人多费耐心,小弟是新手。