×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

建一个自己server control 代替DropDownList

Public Class myDropDownList
Inherits Control
Implements INamingContainer

Protected Overrides Sub CreateChildControls()

Dim DropDownList1 As New System.Web.UI.WebControls.DropDownList
DropDownList1.DataSource =
DropDownList1.DataMember =
DropDownList1.DataValueField =

DropDownList1.DataBind()

Me.Controls.Add(DropDownList1)

End Sub

End Class

用这个代替DropDownList应该能行. 如果不同DataList's ITEM中的DropDownList用不同数据绑定, 也可以做到
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / ASP。NET问题, 谢谢!
    有没有哪位朋友在DATALIST中用过DROPDOWNLIST?把DROPDOWNLIST拖进DATALIST以后, 虽然有ID,但是在behind code中找不到这个DROPDOWNLIST的定义, 硬要用当然是找不到。假如要用的话, 数据如何才能绑定?
    • 自己到开头处根据id,定义一个不就行了?然后,再设datasource = your datalist.
      • 不是的,那个DATALIST是个container, 我想把dropdownlist做成它的子控件。
    • 不知道你想怎么用?
      我这样使用是好使的:

      (1)string [] m_aryStr = new string [] {"abc", "def", "ghi", "jki"} ;
      (2)Draw a datalist1 on a Web form and set datalist1.datasource = m_aryStr ;
      (3)Drag dropdownlist1 into datalist1(when designing the template) and right click dropdownlist1 to get the property dialog. set the databinding property of dropdownlist1 , make "datasource" the bindable property and bind container.dataitem to datasource.

      (4)end the design of template

      (5) call databind() in page_load().

      (6) ok now
      • 谢谢。
        偶的dropdownlist的数据源跟datalist不一起,只是根据datalist绑定数据中的某一个值来设定dropdownlist 中default选的值,就想试试直接这样是不是可行,不行的话用其它方法。
    • 建一个自己server control 代替DropDownList
      Public Class myDropDownList
      Inherits Control
      Implements INamingContainer

      Protected Overrides Sub CreateChildControls()

      Dim DropDownList1 As New System.Web.UI.WebControls.DropDownList
      DropDownList1.DataSource =
      DropDownList1.DataMember =
      DropDownList1.DataValueField =

      DropDownList1.DataBind()

      Me.Controls.Add(DropDownList1)

      End Sub

      End Class

      用这个代替DropDownList应该能行. 如果不同DataList's ITEM中的DropDownList用不同数据绑定, 也可以做到
      • 谢谢, 就是这样解决的。
    • Use FindControl() method of container control, [DataList].FindControl(DrowDownListID)
      • Datalist isn't just a container control. It is a templated control. Can't use findcontrol() method to find control contained in template
        • It works to use e.Item.FindControl at DataList.ItemDataBound event's handler.
          • Yes, you are right. Should be e.Item.FindControl(), since the dropdownlist controls are repeating in Items. Can be any events passing e relate to item, like selectedIndexChanged.