Click here to Skip to main content
Rate this: bad
good
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
good
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[^]
 
Regards
Pawan
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
Sachin Shinde11088 at 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
good
Please Sign up or sign in to vote.

Solution 3

Try this...
 
<form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
             AutoGenerateEditButton="True" onrowcancelingedit="GridView2_RowCancelingEdit" onrowediting="GridView2_RowEditing"
             >
            <Columns>
                <asp:TemplateField HeaderText="Name">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtNameGrid" runat="server" Text ='<%# Bind("Name") %> ' ></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %> '></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Age">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtAgeGrid" runat="server" Text = '<%# Bind("Age") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Age") %> '></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
     </div>
     <div>
     <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
     <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
     </div>
    </form>
 

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;
GridView2.DataBind();


}
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView2.EditIndex = e.NewEditIndex;
GridView2.DataSource = obj;
GridView2.DataBind();
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;
GridView2.DataBind();

}
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
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