GridView 使用 DropDownList 出现绑定空值的异常处理
来源:互联网 发布:ubuntu wine qq 16.04 编辑:程序博客网 时间:2024/04/28 23:41
<asp:TemplateField HeaderText="父节点">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource_ZipNode" DataTextField="DistrictDesc"
DataValueField="DistrictId" SelectedValue='<%# Bind("ParentId") %>'
AppendDataBoundItems="True" ondatabinding="DropDownList1_DataBinding"
ondatabound="DropDownList1_DataBound"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Enabled="false"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource_ZipNode" runat="server"
ConnectionString="<%$ ConnectionStrings:connStr %>"
SelectCommand="prd_SelectDistrictNodes" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ParentId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
要点已经标出
//上面这种方法有局限性,还有一种通用的方法
<EditItemTemplate> 模版里的DropDownList 不用SelectedValue绑定
在GridView事件 _RowUpdating
DropDownList objtemp_ZipId=GV_SheBeiDelete.Rows[e.RowIndex].FindControl("DropDownList3") as DropDownList;
DropDownList objtemp_DvsTypeId = GV_SheBeiDelete.Rows[e.RowIndex].FindControl("DropDownList4") as DropDownList;
e.NewValues["ZipId"] = objtemp_ZipId.Text;
e.NewValues["DvsTypeId"] = objtemp_DvsTypeId.Text;
当然对于编辑模版里的 DropDownList 要写事件 DropDownList4_DataBound
DropDownList obj = sender as DropDownList;
try
{
obj.Text = DvsTypeId_GV_SheBeiDelete; ; //变量,其取值在GridView的RowEditing事件里
}
catch
{
}
- GridView 使用 DropDownList 出现绑定空值的异常处理
- GridView绑定DropDownList的小问题
- GridView绑定DropDownList的小问题
- 关于gridview和dropdownlist的数据绑定
- 绑定DropDownList和GridView
- GridView绑定DropdownList
- gridview动态绑定dropdownlist
- GridView 中绑定 DropDownList
- GridView中DropDownList绑定
- dropdownlist值的绑定
- .NET 使用GridView控件绑定数据源个人出现的错误*
- 清空DropDownList的值
- GridView DropDownList 数据 绑定 RowEditing
- GridView编辑状态绑定DropDownlist时,出现偶数行不能绑定情况
- 绑定DropDownList的中的值
- gridview行编辑时绑定Dropdownlist并选中对应值
- dropdownlist和GridView的简单使用
- 在GridView的Cells中使用Dropdownlist
- 5个简单,但很实用的 css属性
- Linux内核模块编程
- jsp弹出新窗口代码
- Linux 系统启动过程(initrd部分) --- Linux boot process (initrd part)
- 访问 IIS 元数据库失败解决方案
- GridView 使用 DropDownList 出现绑定空值的异常处理
- jquery select search select快速查询定位插件
- JDeveloper使用过程中碰到怪问题的解决
- 文本编辑器editor.php
- “用指定的用户名和密码无法登录到该ftp服务器”解决办法
- Linux 学习第2天 gdb 的安装
- linux下载字体的安装(超级简洁)
- 如何使用不清楚的MavenPlugin
- 关于exe形式编程的一点心得,希望对大家有所帮助