griview绑定数据源后显示调用update方法的实现
来源:互联网 发布:超星网络课答案 编辑:程序博客网 时间:2024/06/03 20:43
通常情况下,不需要调用 Update 在代码中的方法。 数据绑定控件将自动调用 Update 方法时用户执行操作以更新记录。 显式调用 Update 方法如果您想要创建您自己的进程用于更新数据。
语法如下:
public int Update(IDictionary keys,IDictionary values,IDictionary oldValues)
参数
- keys
- Type: System.Collections.IDictionary
要更新的记录行键值。
- values
- Type: System.Collections.IDictionary
要在数据源中更新的行值。
- oldValues
- Type: System.Collections.IDictionary
行值,其计算结果为检测数据冲突。
返回值
Type: System.Int32更新操作所影响的记录数。
下面的示例演示如何以编程方式更新数据源中的记录,用户单击按钮之后。 该代码将 ListDictionary 对象,其中包含的密钥值, ListDictionary 对象,其中包含的原始值和一个 ListDictionary 对象,其中包含这些新值与 Update 方法。
C#代码:
要加上using System.Collections.Specialized;
protected void Reset_Click(object sender, EventArgs e){ ListDictionary keyValues = new ListDictionary(); ListDictionary newValues = new ListDictionary(); ListDictionary oldValues = new ListDictionary(); keyValues.Add("ProductID", int.Parse(((Label)DetailsView1.FindControl("IDLabel")).Text)); oldValues.Add("ProductName", ((Label)DetailsView1.FindControl("NameLabel")).Text); oldValues.Add("ProductCategory", ((Label)DetailsView1.FindControl("CategoryLabel")).Text); oldValues.Add("Color", ((Label)DetailsView1.FindControl("ColorLabel")).Text); newValues.Add("ProductName", "New Product"); newValues.Add("ProductCategory", "General"); newValues.Add("Color", "Not assigned"); LinqDataSource1.Update(keyValues, newValues, oldValues); DetailsView1.DataBind();}下面的示例演示上一示例的标记。
<asp:LinqDataSource ContextTypeName="ExampleDataContext" TableName="Products" EnableUpdate="true" ID="LinqDataSource1" runat="server"> </asp:LinqDataSource> <asp:DetailsView DataSourceID="LinqDataSource1" AllowPaging="True" ID="DetailsView1" runat="server" AutoGenerateRows="False"> <Fields> <asp:templatefield HeaderText="Product ID"><itemtemplate><asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label></itemtemplate></asp:templatefield> <asp:templatefield HeaderText="Product Name"><itemtemplate><asp:Label ID="NameLabel" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label></itemtemplate></asp:templatefield> <asp:templatefield HeaderText="Category"><itemtemplate><asp:Label ID="CategoryLabel" runat="server" Text='<%# Bind("ProductCategory") %>'></asp:Label></itemtemplate></asp:templatefield><asp:templatefield HeaderText="Color"><itemtemplate><asp:Label ID="ColorLabel" runat="server" Text='<%# Bind("Color") %>'></asp:Label></itemtemplate></asp:templatefield> </Fields> </asp:DetailsView> <asp:button ID="Button1" Text="Reset with default values" runat="server" onclick="Reset_Click" />
阅读全文
0 0
- griview绑定数据源后显示调用update方法的实现
- DataGridView绑定数据源后限制列显示
- 数据绑定后显示的方法
- DropDownList绑定数据源的方法
- DropDownList绑定数据源的方法
- WPF中ListView绑定数据源后居中显示
- GridView等组件绑定后台数据源列的绑定方法,onclick方法调用中含有Eval绑定如何调用js方法
- flex三种绑定数据源的方法
- GridView后台绑定数据源的分页方法
- C# ComboBox 数据源绑定后数据的添加
- 数据源绑定JNDI步骤以及绑定后数据源存放路径
- Java方法调用的绑定
- Java方法调用的绑定
- 如何限制.net2.0 DataGridView绑定数据源后显示所有属性列
- 动态数据源的绑定
- DataGridComboBoxColumn绑定后显示空白的问题
- SSH的update实现方法
- c#中手动给dataGridView绑定数据源的方法
- java字符串四道课后习题
- set和multiset使用方法 (STL)
- python绘制神经网络(转载)
- 异常浅析
- 嵌入式系统概述(学习笔记)
- griview绑定数据源后显示调用update方法的实现
- CSS小功能
- 学习linux内核(二)
- 常用正则表达式
- Powershell命令笔记
- oracle 序列和触发器的联合使用
- mysql我所遇到的问题case when then的使用
- 常见浏览器兼容性
- 10-S3C2440驱动学习(六)嵌入式linux-触摸屏设备驱动