473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to Update modified text into gridview

1 New Member
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 1218

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

Similar topics

1
2305
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 combo boxes. I know of the column(n) method (derived from the third combo). However if the user does any sort of manipulation in the first or second combo then the value in the text box doesn't change accordingly. Is there any other way to update...
1
3425
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 end date), and 2 buttons. When the user clicks the button, it will invoke the calendar form. Here's the code fragment for the first form: Private Sub Command1_Click() Dim instanceCalendarForm As CalendarForm Set instanceCalendarForm = New...
1
1181
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" ForeColor="#333333" GridLines="None" DataKeyNames="ADid"> and it is my update query: UPDATE tblAds SET ADName = @ADname, ADType = @ADType, ADPriority =
0
2385
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 method has worked for 1 gridview and failed for the second gridview. Here is my gridview : <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>" SelectCommand="ViewForecast"...
4
2598
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 something really easy, but I cannot see it. The stored procedue works when run in QA. Can someone tell me what I am doing wrong/missing that is keeping the delete command from working in the gridview? Thank you. I am trying to delete a row out of...
0
3879
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. " Normally i create a number if update commands for each single line on edit due to the type of data selected (multi tables , ...) I can get around this by creating a dummy command like select 1 where 1=3
0
1515
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 the fields that matches the string and binds it to the gridview. It is working perfectly without the full page refresh. The problem is that when I type something fast, it loses the focus, and i needed to click the textbox again with mouse in order...
0
838
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" Runat="Server" ConnectionString="<%$ ConnectionStrings:ConnectionStringTraining %>" ProviderName="<%$ ConnectionStrings:ConnectionStringTraining.ProviderName %>" SelectCommand="SELECT...
0
923
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 Fields I am using a Gridview to call this object method. Which overload do you suggest I use and how do I pass it from the Gridview to the business object method?
0
1163
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 code: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"> <span style="font-size: 24pt">
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.