datagrid中使用dropdownlist编辑模版时遇到问题
前2天我做的财务管理系统中需要用到datagrid控件来显示用户信息,为了能够编辑用户信息,我参照微软的asp.net入门套件ASP.NET Time Tracker Starter Kit (VBVS)中在datagrid中使用编辑模版。 在问题没解决之前,点击datagrid中的编辑始终报下面错误:
’==================
‘===================
下面是datagrid的html文件:
AllowPaging="true" CellPadding="3" PageSize="15" AutoGenerateColumns="false" EnableViewState="true" OnUpdateCommand="dguserdetail_UpdateCommand" OnEditCommand="dguserdetail_OnEdit" OnCancelCommand="dguserdetail_OnCancel">
<AlternatingItemStyle BackColor="#F9F9F9"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="姓名">
<HeaderStyle Width="100px"></HeaderStyle>
<ItemTemplate>
<asp:label ID="username" Text=' <%# DataBinder.Eval(Container.DataItem, "username").ToString() %> ' Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="密码">
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:label ID="password" Text=' <%# DataBinder.Eval(Container.DataItem, "password").ToString() %> ' Runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox runat="server" CssClass="Standard-text" ID="txtpassword" Text='<%#DataBinder.Eval(Container.DataItem, "password").ToString()%>' Width="100" MaxLength="255">
</asp:textbox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="电子邮箱">
<ItemTemplate>
<asp:label ID="email" Text=' <%# DataBinder.Eval(Container.DataItem, "email").ToString() %> ' Runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox Width="135px" AutoPostBack=false CssClass="Standard-text" Runat="server" ID="txtemail" Text='<%# DataBinder.Eval(Container.DataItem, "email").ToString() %> ' />
<asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server" ErrorMessage="电子邮件无效" ControlToValidate="txtemail"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:regularexpressionvalidator>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="权限">
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:label ID="authority" Text=' <%# DataBinder.Eval(Container, "DataItem.authority") %>' Runat="server" />
</ItemTemplate>
<edititemtemplate>
<asp:dropdownlist Width="100px" ID="DDauthority" DataSource='<%# bindDropDownList %>' Runat="server">
</asp:dropdownlist>
</edititemtemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="update" HeaderText="編辑" CancelText="cancel"
EditText="edit">
</asp:EditCommandColumn>
</Columns>
</asp:datagrid>
最初的页面显示如下:
按下编辑后的页面:
对于编辑列中的edit,update,cancel需要用到下面的是件:
'==============================
dguserdetail.EditItemIndex = e.Item.ItemIndex //'获取被选中的行索引
'Saves current info on temporary, use later in dguserdetail_Itembound()
studatagrid.username = CType(e.Item.FindControl("username"), Label).Text.Trim
studatagrid.password = CType(e.Item.FindControl("password"), Label).Text.Trim
studatagrid.email = CType(e.Item.FindControl("email"), Label).Text.Trim
studatagrid.authority = CType(e.Item.FindControl("authority"), Label).Text.Trim
'=======================================
SetBind() //'最后问题解决的关键语句
'=======================================
' During in-line-editing mode this selects corresponding items for dropdowns and text boxes.
'==========================================
Private Sub ItemDataBound()Sub ItemDataBound(ByVal sender As Object, _
ByVal e As DataGridItemEventArgs) Handles dguserdetail.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim currentCbo As DropDownList = CType(e.Item.FindControl("DDauthority"), DropDownList)
currentCbo.SelectedIndex = currentCbo.Items.IndexOf(currentCbo.Items.FindByText(studatagrid.authority))
End If
End Sub
Protected Sub dguserdetail_UpdateCommand()Sub dguserdetail_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dguserdetail.UpdateCommand
Dim item As DataGridItem = dguserdetail.Items(dguserdetail.EditItemIndex)
If e.CommandName = "Update" Then
If e.Item.ItemType = ListItemType.EditItem Then '只有在编辑按下以后才能提交
Dim username As String
Dim password As String
Dim email As String
Dim authority As String
Dim authorityId As Integer
username = CType(e.Item.FindControl("username"), Label).Text
password = CType(e.Item.FindControl("txtpassword"), TextBox).Text
email = CType(e.Item.FindControl("txtemail"), TextBox).Text
authority = CType(e.Item.FindControl("ddauthority"), DropDownList).SelectedItem.Value
authorityId = IIf(authority = "系统管理员", 1, 0)
' Save the dguserdetail object.
Try
SqlHelper.ExecuteNonQuery(strconn, "updateuser", username, password, email, authorityId)
Catch
End Try
End If
' Quit in-line-editing mode.
dguserdetail.EditItemIndex = -1
SetBind()
End If
End Sub
Protected Sub dguserdetail_OnCancel()Sub dguserdetail_OnCancel(ByVal sender As [Object], ByVal e As DataGridCommandEventArgs) Handles dguserdetail.CancelCommand
dguserdetail.EditItemIndex = -1
SetBind()
End Sub 'TimeEntryGrid_OnCancel
转载于:https://www.cnblogs.com/lvxuehui/archive/2005/04/30/148263.html
datagrid中使用dropdownlist编辑模版时遇到问题相关推荐
- DataGrid中添加DropdownList时的数据绑定
在HTML中,指定DropDownList的数据源是哪个函数提供: <asp:TemplateColumn HeaderText="发送人"> <Ite ...
- Linux中vi命令编辑文件时显示行号
vi file_name 直接进去时没有行号显示的,这时可以进入末行模式(文件末尾出现冒号)时输入 : set nu 效果如图: 这种做法有个弊端,在退出编辑后,再次进入编辑时行号就不再显示了. 配置 ...
- Ubuntu中使用vi编辑时方向键乱码或退格键不能使用解决方法
1.引言 Ubuntu中使用vi编辑文本文件时,会出现按上下左右方向键时,出现ABCD等字符,而且退格键也不起作用,如何解决这个问题? 2.解决方法 2.1 原因 由于Ubuntu 预安装的是vim ...
- linux图片裁剪工具,Linux_在Linux的命令行中实现裁剪图片的方法 ,当涉及到在Linux中转换或编辑 - phpStudy...
在Linux的命令行中实现裁剪图片的方法 当涉及到在Linux中转换或编辑图像文件时,ImageMagick毫无疑问是最为熟知的一体化软件之一.它包含了一整套命令行工具,用以显示.转换,或复制超过20 ...
- 【ASP.NET】第八课——GridView 控件的编辑功能优化,GridView控件中嵌套DropDownList控件
知识点:掌握 GridView 的编辑.高亮显示的功能 .GridView控件中嵌套DropDownList控件获取数据源. [ASP.NET]第七课--数据绑定和 GridView 控件的使用 重点 ...
- 在DataGrid(WebControl)中处理DropDownList事件的补充说明
由于DropDownList没有CommandName属性,所以不能用ItemCommand事件,不过你可以这样做: 在DataGrid的模板列中加入的DropDownList控件 <asp:D ...
- 在word中利用Endnote导入文献时提示“无法编辑range”的解决办法-基本上通过以下方法都可以解决
在word中利用Endnote导入文献时提示"无法编辑range"的解决办法 注意:在处理这个问题之前,请复制word以备份我们要处理的word文件,否则后期如果我们调整了word ...
- CSDN中编辑文章时,如何去除图片水印?
CSDN中编辑文章时,如何去除图片水印? 前言 场景 前言 作为新手,第一次发布文章时,发现上传的图片为什么多了水印,不美观也影响观看,所以希望能去除掉,在此保存一下操作步骤. 场景 1.上传图片,可 ...
- 在DataGrid中添加一个LookUpColumn,以比较灵活地实现DictValue值代替DictID值显示.
在一个项目中,我遇到这样一个问题: 数据库字段只存储了一个字典ID1,在DataGrid中显示时,需要用相应的字典Value1来代替字典ID1显示.解决这个问题一般有两个方法: 方法1: 数据库查询 ...
最新文章
- linux驱动篇之 driver_register 过程分析(二)bus_add_driver
- BZOJ1398: Vijos1382寻找主人 Necklace 字符串最小表示法
- java怎样实现自定义过滤关键词_SpringSecurity学习之自定义过滤器的实现代码
- (转)Spring Boot(九):定时任务
- 正在迷茫的你,为什么不考虑这份工作呢?
- java字符转为数字_java判断字符串是否可以转为数字
- Jug 并行处理框架
- 计算机操作系统(第四版)课后习题答案(完整版)[转载]
- 解决电脑启动蓝屏出现Recovery—错误代码0xc000014
- 第五篇 python计算新版个人所得税
- 现代企业管理-组织与领导
- [读书笔记]结绳记事
- MyBatis之Base64加密数据源
- Mac装了微信小助手,微信闪退怎么办?
- 用程序解密爱因斯坦经典难题
- 合泰HT66F018编程介绍
- lucksheet表格操作插件的使用
- 宠辱不惊,看庭前花开花落;去留无意,望天空云卷云舒
- 使用EasyUI combobox的loadData 加载数据
- 湖南文旅数据中心:湖南文旅数据早知道(9月8日)
热门文章
- html使用js的变量_JS变异小技巧:使用JavaScript全局变量绕过XSS过滤器
- 怎么查看python是否安装好了pyinstaller_Python PyInstaller安装和使用教程(详解版)...
- c语言取奇数位构成新数,2、给定程序MODI1.C中函数fun的功能是:从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中.高位...
- 用友t3服务器文件丢失,服务器系统损坏数据恢复
- 机器如何区分和判定指令和数据
- Codeforces Round #491 (Div.2)
- 乐山电子计算机职业学院,学校介绍
- pytorch 之 有关交叉熵函数使用的几点说明
- Excel酷炫技能,批量修改工作表名称,让你的工作事半功倍
- netstat 和 losf