Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello, i'm new to asp.net so please bare with me

so far i have a grid view bound to an xml data source, when the user clicks on edit on whatever row it will open up a new view, this view holds 3 text boxes. Each textbox is populated with the selected row's data.

my question is how can i update the value of the gridview's row by clinking on the "update" button located in this view

the view in the aspx file :

<asp:View ID="edit" runat="server" >

id <asp:TextBox ID="editid" runat="server" >
name
<asp:TextBox ID="editname" runat="server" >
info
<asp:TextBox ID="editinfo" runat="server" >

<asp:Button Text="update" ID="update" runat="server" OnClick="update_Click" />




linked it with the gridview when the user clicks on edit.


code behind file :

protected void gv1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "eddit")
{
//view 2 used for editing and updating

MultiView1.ActiveViewIndex = 2;
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
//linked my textboxes to the labels in the gridview
editid.Text = (row.FindControl("labelid") as Label).Text;
editname.Text = (row.FindControl("labelname") as Label).Text;
editinfo.Text = (row.FindControl("labelinfo") as Label).Text;


}
}


how do i save the values i typed in the text boxes to the gridview's selected row or save it to the xml file?

protected void update_Click(object sender, EventArgs e)
{
// i want to add some code here to update the values from the textbox to the selected row. is this possible
}


i'm sorry for the stupid question but i am at a loss.

thank you very much for your help, and please bare with me i am a beginner in this
Posted
Updated 13-Apr-14 0:29am
v2

1 solution

For this, you have to take something inside RowCommand, which is unique like some ID or something. Inside the View, store it in a HiddenField.

Inside Update Button Click Event, get the ID value and update that particular row in XML by searching with the ID.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900