Click here to Skip to main content
12,299,315 members (54,403 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
I want to display a Gridview data onto forms Text Box controls after clicking an edit button.
what should i do.
Edit button is in a Grid views item template column.
please give me simple solution.
Posted 17-Dec-12 17:29pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you want to let the user edit the values in the gridview once they click on some "Edit" button in the gridview row then you can use the editItemTemplate. You might refer a simple article to do so on codeproject at Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List[^]

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Displaying Gridviews data onto the forms Text box[^]

in this link you can get basic idea.
Sachin Shinde11088 18-Dec-12 0:46am
hey VishwaKL i have read ur article.
bt its not working in my case yaar.
is der need to set any property.
please let me know
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Try this...

<form id="form1" runat="server">
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
             AutoGenerateEditButton="True" onrowcancelingedit="GridView2_RowCancelingEdit" onrowediting="GridView2_RowEditing"
                <asp:TemplateField HeaderText="Name">
                        <asp:TextBox ID="txtNameGrid" runat="server" Text ='<%# Bind("Name") %> ' ></asp:TextBox>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %> '>

public class Person
    public string Name { get; set; }
    public int Age { get; set; }
    public int key { get; set; }

public List<Person> obj = new List<Person>();
protected void Page_Load(object sender, EventArgs e)
obj = new List<Person>{(new Person{ Name = "ajai", Age = 50 ,key =10})};
obj.Add(new Person { Name = "Manoj", Age = 100, key = 20 });
obj.Add(new Person { Name = "Sanjay", Age = 150, key = 30 });

GridView2.DataSource = obj;

protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
GridView2.EditIndex = e.NewEditIndex;
GridView2.DataSource = obj;
TextBox editName = (TextBox)GridView2.Rows[e.NewEditIndex].Cells[0].FindControl("txtNameGrid");
TextBox editAge = (TextBox)GridView2.Rows[e.NewEditIndex].Cells[1].FindControl("txtAgeGrid");
txtName.Text = editName.Text;
txtAge.Text = editAge.Text;
protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
GridView2.EditIndex = -1;
GridView2.DataSource = obj;


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100