what is the handiest way to update only the updated rows (only the
checkbox column) in this gridview? what is a handy way to check wether the row was updated?
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();
}
}
protected void btnUpdate_Click1(object sender, EventArgs e)
{
foreach (GridViewRow rw in GridView1.Rows)
{
CheckBox thiscontrol = (CheckBox)rw.Cells[0].FindControl("cb");
var ch = thiscontrol.Checked;
//only update the updated rows?
}
}
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>