在formview控件模板列中使用两个DropDownList控件进行联动时的操作方法
2006-11-19 10:38
357 查看
1、在formview控件模板列中放入两个DropDownList控件
2、将第一个控件按常规方法加入数据源,设置要显示的字段名和字段值,并与formview中的相应字段关联,关设置为启用autopostback
3、给第二个DropDownList控件加入数据源,设置要显示的字段名和字段值,在其DataBound事件中加入如下代码
Protected Sub DropDownList2_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList = CType(sender, DropDownList)
'指定下拉框的父控件
Dim frmv As FormView = CType(ddl.NamingContainer, FormView)
If Not frmv.DataItem Is Nothing Then
Dim strcity As String = CType(frmv.DataItem, DataRowView)("SmallClassID")
'清除下拉框的选择项
ddl.ClearSelection()
'在下拉框的列表项中找到值
Dim li As ListItem = ddl.Items.FindByValue(strcity)
If Not li Is Nothing Then
li.Selected = True
End If
'找到控件DropDownList2
ddl = CType(frmv.FindControl("DropDownList2"), DropDownList)
'邦定数据
If Not ddl Is Nothing Then
ddl.DataBind()
End If
4000
End If
End Sub
4、给formview的ItemInserting事件加入如下代码:
'当触发formview的插入数据的项时进行下列操作
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
将DropDownList2的值赋给formview控件中的插入参数SmallClassID()
Dim strprov As Int32 = CType(CType(sender, FormView).FindControl("DropDownList2"), DropDownList).SelectedValue
e.Values("SmallClassID") = strprov
End Sub
2、将第一个控件按常规方法加入数据源,设置要显示的字段名和字段值,并与formview中的相应字段关联,关设置为启用autopostback
3、给第二个DropDownList控件加入数据源,设置要显示的字段名和字段值,在其DataBound事件中加入如下代码
Protected Sub DropDownList2_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList = CType(sender, DropDownList)
'指定下拉框的父控件
Dim frmv As FormView = CType(ddl.NamingContainer, FormView)
If Not frmv.DataItem Is Nothing Then
Dim strcity As String = CType(frmv.DataItem, DataRowView)("SmallClassID")
'清除下拉框的选择项
ddl.ClearSelection()
'在下拉框的列表项中找到值
Dim li As ListItem = ddl.Items.FindByValue(strcity)
If Not li Is Nothing Then
li.Selected = True
End If
'找到控件DropDownList2
ddl = CType(frmv.FindControl("DropDownList2"), DropDownList)
'邦定数据
If Not ddl Is Nothing Then
ddl.DataBind()
End If
4000
End If
End Sub
4、给formview的ItemInserting事件加入如下代码:
'当触发formview的插入数据的项时进行下列操作
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
将DropDownList2的值赋给formview控件中的插入参数SmallClassID()
Dim strprov As Int32 = CType(CType(sender, FormView).FindControl("DropDownList2"), DropDownList).SelectedValue
e.Values("SmallClassID") = strprov
End Sub
相关文章推荐
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- ASP.NET 两个DropDownList控件的动态联动
- MultiAutoCompleteTextView和AutoCompleteTextView两个自动完成功能控件的使用
- My97DatePicker 日历控件使用,两个日历控件联动.
- DropDownList ListBox GridView DataList Repeater FormView DetailsView 数据绑定控件详解
- 在ASP.NET 2.0中操作数据:使用FormView 的模板
- FormView控件使用
- Scott Mitchell 的ASP.NET 2.0数据教程之十四:使用FormView 的模板
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- [翻译]Scott Mitchell 的ASP.NET 2.0数据教程之十四:使用FormView 的模板
- 在ASP.NET 2.0中操作数据之十四:使用FormView 的模板
- 梅花雨时间控件在asp.net中的使用,平台为2005(注:未在有模板的情形下进行测试)
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- 使用Ajax实现DropDownList和ListBox的联动以及两个ListBox之间数据的移动
- [翻译]Scott Mitchell 的ASP.NET 2.0数据教程之十四:使用FormView 的模板
- MultiAutoCompleteTextView和AutoCompleteTextView两个自动完成功能控件的使用
- Scott Mitchell 的ASP.NET 2.0数据教程之十四:使用FormView 的模板
- FORM进阶1——使用FOLDER模板进行开发
- 访问formview模板内控件