BoundField be changed to textbox in .Net 4.0

本文介绍了一个ASP.NET GridView控件的使用示例,展示了如何设置GridView以显示包含姓名和ID的数据,并允许用户通过点击按钮来触发编辑操作。代码中包含了具体的实现细节。

Question:
<asp:GridView ID="GridView1"   AutoGenerateColumns="False" DataKeyNames="Id" 
            runat="server" onrowediting="GridView1_RowEditing">
        <Columns>
        <asp:BoundField DataField="Id" HeaderText="ID" Visible="False" />
        <asp:BoundField DataField="FirstName" HeaderText="First Name" />
        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton ID="imageButton" AlternateText="Edit" CausesValidation="false" CommandName="Edit" runat="server" /> 

            </ItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>


public partial class _Default : System.Web.UI.Page
    {
        public class Person
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public int Id { get; set; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<Person> people = new List<Person>() { new Person { FirstName = "Mike", Id = 1, LastName = "Myers" }, new Person() { FirstName = "John", Id = 2, LastName = "Smith" } };
                GridView1.DataSource = people;
                GridView1.DataBind();
            }
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }
    }

Solution:
change this 'edit' to other string. ex. 'edit1'...
<asp:ImageButton ID="imageButton" AlternateText="Edit" CausesValidation="false" CommandName="Edit" runat="server" /> 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/310974/viewspace-1985053/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/310974/viewspace-1985053/

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值