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

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个附件,已经成功下载328次)

最值得关注的外文源代码

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字内
请如实评论
本源代码共评论59次,此处显示最近20次评论! 查看所有评论

杨小妞爱忘词  2013年10月09日
xiexie
kennyshi  2013年06月25日
不错
gn_2012  2013年03月17日
学习一下
chp2008  2012年10月24日
好的
ZZVENUS  2012年09月11日
学习学习
pp8821  2012年02月13日
谢谢分享。。。
情缘  2011年12月01日
反反复复
cx4359481  2011年11月25日
谢谢分享
情缘  2011年11月25日
呵呵
jinjianmin  2011年10月30日
学习一下
modpal  2011年10月17日
不知道是什么,先来学习
longkim  2011年09月20日
不错
longkim  2011年09月20日
不知道是什么,先来学习
mayiengly  2011年04月22日
的师傅萨菲
zensst  2011年04月03日
分享是一种快乐
abcdefaaaaaa  2011年04月02日
sassasa
abcdefaaaaaa  2011年04月02日
wqqwwqeqeqwewe
abcdefaaaaaa  2011年04月02日
assasass
cena  2011年01月27日
谢谢!值得试试
彷徨者  2009年09月16日
不知道会不会产生有了postback事件后丢失模板的现象,我做过这些用代码添加模板的例子,但是会产生数据丢失的现象!要不然就是postback后自动又添加一列!谁又好的方法 发Email zhulanyang@gmail.com交流!
字数在300字内
请如实评论
200万国内源码搜索
CopyRight (C) codesoso.com 2007-2009 All Rights Reserved zhihuishi   免责声明