2
什么是最新的方法来更新此GridView中更新的行(只有复选框列)?什么是方便的方式来检查行更新?如何只更新gridview中更新的行?
C#
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<customer> listCustomer = new List<customer>();
customer cust1 = new customer(){name="fred",email="[email protected]",jobless="true"};
customer cust2 = new customer(){name="mark",email="[email protected]",jobless="false"};
listCustomer.Add(cust1);
listCustomer.Add(cust2);
GridView1.DataSource=listCustomer;
GridView1.DataBind();
}
}
保护无效btnUpdate_Click1(对象发件人,EventArgs的) { 的foreach(在GridView1.Rows GridViewRow RW) { 复选框thiscontrol =(复选框)rw.Cells [0]。的FindControl( “CB”); var ch = thiscontrol.Checked; //只更新更新的行? }}
public class customer
{
public string name { get; set; }
public string email { get; set; }
public string jobless { get; set; }
}
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="gridviewUpdate._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="jobless" runat="server" Checked='<%# Eval("jobless").ToString().Equals("true") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="email" />
<asp:BoundField DataField="name" />
</Columns>
</asp:GridView>
</div>
下面是详细信息,关于什么akash88说http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx – 2012-03-20 10:11:11