【问题标题】:how to update only the updated rows in gridview?如何仅更新gridview中的更新行?
【发布时间】:2012-04-04 15:00:54
【问题描述】:

在此网格视图中仅更新已更新行(仅复选框列)的最便捷方法是什么?检查行是否更新的便捷方法是什么?

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="fred@mail.com",jobless="true"};
            customer cust2 = new customer(){name="mark",email="mark@mail.com",jobless="false"};
            listCustomer.Add(cust1);
            listCustomer.Add(cust2);
            GridView1.DataSource=listCustomer;
            GridView1.DataBind();
        }


    }

protected void btnUpdate_Click1(object sender, EventArgs e) { foreach(GridView1.Rows 中的 GridViewRow rw) { CheckBox thiscontrol = (CheckBox)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>

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    你可以使用GridView.RowUpdating事件.....

    <asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" OnRowUpdating="TaskGridView_RowUpdating">
    

    在后面的代码中,

     protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
      {    
        //logic code here
      }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多