ITPub博客

首页 > 应用开发 > IT综合 > BoundField be changed to textbox in .Net 4.0

BoundField be changed to textbox in .Net 4.0

原创 IT综合 作者:gavinlee 时间:2016-02-01 10:37:38 0 删除 编辑

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博客 ” ,链接:https://blog.itpub.net/310974/viewspace-1985053/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    51
  • 访问量
    795695