net将defult值与dropdownlist

net将defult值与dropdownlist

本文介绍了如何使用vb.net将defult值与dropdownlist绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Protected Sub DdlCity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlCity.SelectedIndexChanged
       Dim sql As String
       Dim cityid As String = ""
       cityid = DdlCity.SelectedValue

       sql = "   SELECT     collegename,detailsid  FROM  tdetails where cityid=" & cityid & ""

       ddlbranch.DataSource = Hari.Utility.db.GetRecodeDS(sql)
       ddlbranch.DataTextField = "Collegename"
       ddlbranch.DataValueField = "detailsid"
       ddlbranch.DataBind()



   End Sub









当我在ddlcity中选择城市时,只有那些大学在ddlbranch中显示在选定的城市..我想要显示一个ddlbranch中的更多文本,在ddlcity上选择索引更改,命名为select all。我该怎么办?





when i select city in ddlcity then only those college are show in ddlbranch which are in selected city.. i want to show one more text in ddlbranch that name "select all" on ddlcity select index change. how can i do it?

推荐答案

1. DropDownList1.Items.Add(New ListItem("Select All", "-1"))
2. DropDownList1.Items.Add("Select All")



第一种方法将添加值为-1的项目

第二种方法将为两个文本添加包含全选的项目和价值。



如果你想在特定索引处添加项目,请使用以下代码


1st approach will add item with value "-1"
2nd approach will add item containing "Select All" for both text and value.

And if you want to add item at specific index then use following code

DropDownList1.Items.Insert(0, New ListItem("Select All", "-1"))





它会在第一个时添加一个项目下拉列表的索引。



It will add a item at the first index of the dropdownlist.


这篇关于如何使用vb.net将defult值与dropdownlist绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 04:30