473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Unable to Update modified text into gridview

Hi
In this code everything works fine without any errors, when i edit the row it goes well, but when i change the text in the textbox and press update it still shows the same in gridview row. it doesn't update the latest modified text into GridView. Can u please help me...i was struck here from many days.


Here is my code...

Design:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="5" AutoGenerateColumns="false" OnRowCommand="Gridview1_RowCommand"
  2.     OnPageIndexChanging="GridView1_PageIndexChanging" Width="933px"  HorizontalAlign="Center" OnRowEditing="GridView1_RowEditing"
  3.      OnRowCancelingEdit="GridView1_RowCanceling" OnRowUpdating="GridView1_RowUpdating"  DataKeyNames="id" >
  4.    <HeaderStyle Font-Names="Arial" Width="100px" BackColor="ForestGreen" ForeColor="Black" />
  5.    <PagerSettings FirstPageText="last" NextPageText="first" />   
  6.    <Columns>
  7.    <asp:BoundField HeaderText="Date" DataField="Date" >
  8.        <ItemStyle Width="150px" />
  9.    </asp:BoundField>
  10.    <asp:TemplateField HeaderText="Update" >
  11.    <ItemTemplate>
  12.    <asp:Label ID="Updatelbl" runat="server" Text='<%#Eval("Update")%>'> </asp:Label>
  13.    </ItemTemplate>
  14.    <EditItemTemplate>
  15.    <asp:TextBox ID="UpdateTxt" runat="server" TextMode="MultiLine" ReadOnly="false" Text='<%#Eval("Update")%>' Height="25" Width="650"></asp:TextBox>
  16.    </EditItemTemplate>
  17.    </asp:TemplateField>
  18.     <asp:TemplateField HeaderText="Action">
  19.     <ItemTemplate>
  20.     <asp:LinkButton ID="Editbtn" Text="Edit" runat="server" CommandName="Edit"/>
  21.     </ItemTemplate>
  22.     <EditItemTemplate>
  23.     <asp:LinkButton ID="Updatebtn" Text="Update" runat="Server" CommandName="Update" />
  24.  
  25.     <asp:LinkButton ID="Cancelbtn" Text="Cancel" runat="server" CommandName="Cancel" /> 
  26.     </EditItemTemplate>
  27.     </asp:TemplateField>
  28.    </Columns>   
  29.    </asp:GridView>
  30.  
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         showupdates();
  4.         GridView1.DataBind();
  5.     }
  6.  
  7.     protected void Button1_Click1(object sender, EventArgs e)
  8.     {
  9.         if (!Page.IsPostBack)
  10.         {
  11.             if (TextBox1.Text != "")
  12.             {
  13.                 string xmlFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "\\XMLfile.xml";
  14.                 XmlDocument xmlDoc = new XmlDocument();
  15.                 xmlDoc.Load(xmlFilePath);
  16.                 XmlElement newtasks = xmlDoc.CreateElement("Tasks");
  17.                 XmlElement newupdate = xmlDoc.CreateElement("Update");
  18.                 XmlElement newid = xmlDoc.CreateElement("id");
  19.                 XmlNodeList List = xmlDoc.SelectNodes("/Updations/Tasks/id");
  20.                 int nid = List.Count;
  21.                 if (nid != 0)
  22.                     nid++;
  23.                 else
  24.                     nid = 1;
  25.                 newid.InnerText = nid.ToString();
  26.                 newtasks.AppendChild(newid);
  27.                 XmlElement date = xmlDoc.CreateElement("Date");
  28.                 date.InnerText = DateTime.Now.ToString("dd-MMM-yyyy");
  29.                 newupdate.InnerText = TextBox1.Text;
  30.                 newtasks.AppendChild(date);
  31.                 newtasks.AppendChild(newupdate);
  32.                 xmlDoc.Save(xmlFilePath);
  33.                 xmlDoc.DocumentElement.InsertAfter(newtasks, xmlDoc.DocumentElement.LastChild);
  34.                 FileStream fsxml = new FileStream(xmlFilePath, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);
  35.                 xmlDoc.Save(fsxml);
  36.                 xmlDoc = null;
  37.                 fsxml.Flush();
  38.                 fsxml.Close();
  39.                 fsxml.Dispose();
  40.                 showupdates();
  41.                 TextBox1.Text = "";
  42.             }
  43.         }
  44.     }
  45.  
  46.     protected void showupdates()
  47.     {
  48.             DataSet ds = new DataSet();
  49.             ds.ReadXml(System.AppDomain.CurrentDomain.BaseDirectory + "\\XMLfile.xml");
  50.             GridView1.DataSource = ds.Tables[0];
  51.             GridView1.DataBind();        
  52.     }
  53.  
  54.     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  55.     {
  56.         GridView1.PageIndex = e.NewPageIndex;
  57.         GridView1.DataBind();
  58.     }
  59.     protected void  GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  60.     {
  61.         GridView1.EditIndex = e.NewEditIndex;
  62.         GridView1.DataBind();
  63.     }
  64.     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  65.     {
  66.         int i = e.RowIndex;
  67.         DataSet ds = new DataSet();        
  68.         ds.ReadXml(System.AppDomain.CurrentDomain.BaseDirectory + "\\XMLfile.xml");        
  69.         ds.Tables[0].Rows[e.RowIndex][2] = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("UpdateTxt")).Text;     
  70.         GridView1.EditIndex = -1;
  71.         ds.WriteXml(System.AppDomain.CurrentDomain.BaseDirectory + "\\XMLfile.xml");
  72.         showupdates();
  73.     }
  74.  
Jan 3 '11 #1
0 1202

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Burghew | last post by:
Hi all, I have 3 unbound combo boxes in my form which basically helps me to filter for values. I need to update a text box which will be stored with the value I receive after filtering with the...
1
by: John Davis | last post by:
I am writing a program that allows user to select the date in a calendar, and it will update the text fields automatically. I created 2 forms. The first form has 2 text fields (start date and...
1
by: Saber | last post by:
I have a gridview: <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1"...
0
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this...
4
by: Wannabe | last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page reloads except the row I am trying to delete is still there. I believe it is...
0
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
i get this message when i attempt an update in a gridview where i create the update manuelly. "Updating is not supported by data source 'dsStkStdData' unless UpdateCommand is specified. " ...
0
by: ranjithpanakal | last post by:
I am using a gridview and a textbox in an update panel. My aim is to search and display the items in the gridview based on the value in textbox. When a string is entered into textbox , it searches...
0
by: RobertTheProgrammer | last post by:
Hi, This should be ridiculously simple, but I just can't get the update to work in GridView for ASP.NET. Here's the very simplified code: <asp:SqlDataSource id="ProductsSource"...
0
by: Bobby Edward | last post by:
I have a business object method called UpdateCategory that calls the Update command of a xsd dataset I created. The Update has 5 overloads: DataTable, DataSet, DataRow, DataRows(), Actual...
0
by: =?Utf-8?B?ZWdzZGFy?= | last post by:
Hello, I'm trying to do an update in my gridview but it is not doing for "Descripcion" it but with the other field "IdGrupo" it does and I need to save both, how can I solve this: This is my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.