当前注册人数155278人 邮箱: 密码: 注册新用户 忘记密码
首页 C/C++/MFC C# ASP.NET VB.NET MATLAB   站内搜索 BBS讨论社区 下载代码说明/积分规则
为什么要注册?

1. 可以直接免费从本站下载代码,防止邮件发送不到您的邮箱,或登录不了国外网站

2. 可以设定关键字,当有您关心的代码收录时,邮件通知您

3. 对这里的代码进行评分和评论

4. 可以和大家一起分享你的源代码,得到更多的建议

Edit Individual GridView Cells in ASP.NET

允许只编辑单个单元的GridView控件代码

2007年12月02日
C# (C# 2.0), Windows, .NET (.NET 2.0, .NET 3.5), ASP.NET, Win32, VS (VS2005, VS2008), WebForms
ASP.NET提供的标准GridView控件中,你可以指定EditIndex,编辑整行,不过,也许你只是希望编辑一个单元,本文将给你演示如何只编辑其中的一个单元(可以是一个下拉框),并处理其事件验证。
 
相关知识

绑定时,添加事件:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Get the LinkButton control in the first cell
        LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
        // Get the javascript which is assigned to this LinkButton
        string _jsSingle = ClientScript.GetPostBackClientHyperlink(
            _singleClickButton, "");

        // Add events to each editable cell
        for (int columnIndex = _firstEditCellIndex; columnIndex < 
            e.Row.Cells.Count; columnIndex++)
        {
            // Add the column index as the event argument parameter
            string js = _jsSingle.Insert(_jsSingle.Length - 2, 
                columnIndex.ToString());
            // Add this javascript to the onclick Attribute of the cell
            e.Row.Cells[columnIndex].Attributes["onclick"] = js;
            // Add a cursor style to the cells
            e.Row.Cells[columnIndex].Attributes["style"] += 
                "cursor:pointer;cursor:hand;";
        }
    }
}

源代码原文下载:
Edit Individual GridView Cells in ASP.NET Edit individual GridView cells without putting the entire row into edit mode. Examples using the SqlDataSource and ObjectDataSource controls are included.

源码图片

从本站下载附件及源代码(1个附件,已经成功下载131次)

最值得关注的外文源代码

Event Calendar [ ASP.NET 2.0 / C# ]
Extending the GridView CommandField To Add Delete Confirmation
Gridview Control with print and preview features
DataGrid with built-in filter functionality
评论(评论是增加积分的一个有效途径)
字数在300字内
请如实评论
本源代码共评论23次,此处显示最近16次评论! 查看所有评论

彷徨者  2009年09月16日
不知道会不会产生有了postback事件后丢失模板的现象,我做过这些用代码添加模板的例子,但是会产生数据丢失的现象!要不然就是postback后自动又添加一列!谁又好的方法 发Email zhulanyang@gmail.com交流!
kukumal_apr  2009年03月25日
试看看,
kukumal_apr  2009年03月25日
试看看,
acheng1984  2009年03月20日
very good
dodosong  2009年02月17日
谢谢分享
icotfeng  2009年02月14日
谢谢
dlham  2009年01月12日
看起来和漂亮
wolfzero  2008年12月31日
看起来和漂亮
oatch  2008年12月01日
ok
今生只为你  2008年11月14日
省我不扫视
zhifangsoft  2008年10月14日
这个东东看起来和漂亮
c  2008年09月09日
s
66888888  2008年09月05日
试试
leiryhp  2008年08月28日
允许只编辑单个单元的GridView控件代码
changjiangzhibin  2008年07月02日
挺好的
bj55883  2008年06月10日
学习一下
字数在300字内
请如实评论
CopyRight (C) codesoso.com 2007-2009 All Rights Reserved   免责声明
京ICP备08011023号