SlideShare a Scribd company logo
1 of 4
<StudentDetails>
<Student>
<ID>102</ID>
<Name>Nimit</Name>
<Course>MCA</Course>
<College>Abes</College>
</Student>
</StudentDetails>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:GridView ID="XmlGridView" runat="server"
AutoGenerateColumns="false"
Height="247px" Width="795px" BackColor="White"
BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" ShowFooter="true"
OnRowCancelingEdit="XmlGridView_RowCancelingEdit"
OnRowDeleting="XmlGridView_RowDeleting"
OnRowEditing="XmlGridView_RowEditing"
OnRowUpdating="XmlGridView_RowUpdating">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="LblStuID" runat="server" Text='<
%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtStuID"
runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="LblStuName" runat="server"
Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TxtEditStuName"
runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtStuName"
runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course">
<ItemTemplate>
<asp:Label ID="LblStuCourse" runat="server"
Text='<%# Bind("Course") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TxtEditStuCourse"
runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtStuCourse"
runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="College">
<ItemTemplate>
<asp:Label ID="LblStuCollege" runat="server"
Text='<%# Bind("College") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TxtEditStuCollege"
runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtStuCollege"
runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Operations">
<ItemTemplate>
<asp:Button ID="BtnEdit" runat="server"
CommandName="Edit" Text="Edit" />
<asp:Button ID="BtnDelete" runat="server"
CommandName="Delete" Text="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="BthUpdate" runat="server"
CommandName="Update" Text="Update" />
<asp:Button ID="BtnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="BtnInsert" runat="server"
Text="Insert" OnClick="BtnInsert_Click" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack == true)
{
Get_Xml();
}
}
void Get_Xml()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/XMLFile1.xml"));
if (ds != null && ds.HasChanges())
{
XmlGridView.DataSource = ds;
XmlGridView.DataBind();
}
else
{
XmlGridView.DataBind();
}
}
protected void XmlGridView_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{
XmlGridView.EditIndex = -1;
Get_Xml();
}
protected void XmlGridView_RowEditing(object sender,
GridViewEditEventArgs e)
{
XmlGridView.EditIndex = e.NewEditIndex;
Get_Xml();
}
protected void XmlGridView_RowDeleting(object sender,
GridViewDeleteEventArgs e)
{
Get_Xml();
DataSet ds = XmlGridView.DataSource as DataSet;
ds.Tables[0].Rows[XmlGridView.Rows[e.RowIndex].DataItemIndex].Delete();
ds.WriteXml(Server.MapPath("~/MyXmlFile.xml"));
Get_Xml();
}
protected void XmlGridView_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
int id = XmlGridView.Rows[e.RowIndex].DataItemIndex;
TextBox Name =
XmlGridView.Rows[e.RowIndex].FindControl("TxtEditStuName") as TextBox;
TextBox Course =
XmlGridView.Rows[e.RowIndex].FindControl("TxtEditStuCourse") as TextBox;
TextBox College =
XmlGridView.Rows[e.RowIndex].FindControl("TxtEditStuCollege") as TextBox;
XmlGridView.EditIndex = -1;
Get_Xml();
DataSet ds = XmlGridView.DataSource as DataSet;
ds.Tables[0].Rows[id]["Name"] = Name.Text;
ds.Tables[0].Rows[id]["Course"] = Course.Text;
ds.Tables[0].Rows[id]["College"] = College.Text;
ds.WriteXml(Server.MapPath("~/MyXmlFile.xml"));
Get_Xml();
}
protected void BtnInsert_Click(object sender, EventArgs e)
{
Insert_XML();
}
void Insert_XML()
{
TextBox Stu_Id = XmlGridView.FooterRow.FindControl("TxtStuID") as
TextBox;
TextBox Stu_Name = XmlGridView.FooterRow.FindControl("TxtStuName")
as TextBox;
TextBox Stu_Course =
XmlGridView.FooterRow.FindControl("TxtStuCourse") as TextBox;
TextBox Stu_College =
XmlGridView.FooterRow.FindControl("TxtStuCollege") as TextBox;
XmlDocument MyXmlDocument = new XmlDocument();
MyXmlDocument.Load(Server.MapPath("~/MyXmlFile.xml"));
XmlElement ParentElement = MyXmlDocument.CreateElement("Student");
XmlElement ID = MyXmlDocument.CreateElement("ID");
ID.InnerText = Stu_Id.Text;
XmlElement Name = MyXmlDocument.CreateElement("Name");
Name.InnerText = Stu_Name.Text;
XmlElement Course = MyXmlDocument.CreateElement("Course");
Course.InnerText = Stu_Course.Text;
XmlElement College = MyXmlDocument.CreateElement("College");
College.InnerText = Stu_College.Text;
ParentElement.AppendChild(ID);
ParentElement.AppendChild(Name);
ParentElement.AppendChild(Course);
ParentElement.AppendChild(College);
MyXmlDocument.DocumentElement.AppendChild(ParentElement);
MyXmlDocument.Save(Server.MapPath("~/MyXmlFile.xml"));
Get_Xml();
}

More Related Content

Similar to Xml

Java script form validation
Java script  form validationJava script  form validation
Java script form validationAbhishekMondal42
 
Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5Anekwong Yoddumnern
 
STC Summit 2015 Hypergraphics for visual-first help
STC Summit 2015 Hypergraphics for visual-first helpSTC Summit 2015 Hypergraphics for visual-first help
STC Summit 2015 Hypergraphics for visual-first helpDave Gardiner
 
Vaadin Components @ Angular U
Vaadin Components @ Angular UVaadin Components @ Angular U
Vaadin Components @ Angular UJoonas Lehtinen
 
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docxsri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docxwhitneyleman54422
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface
 
Training in Asp.net mvc3 platform-apextgi,noida
Training in Asp.net mvc3 platform-apextgi,noidaTraining in Asp.net mvc3 platform-apextgi,noida
Training in Asp.net mvc3 platform-apextgi,noidaprav068
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and htmlKevin DeRudder
 
The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180Mahmoud Samir Fayed
 

Similar to Xml (11)

Original exercise
Original exerciseOriginal exercise
Original exercise
 
Java script form validation
Java script  form validationJava script  form validation
Java script form validation
 
Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5Form design by Dreamweaver CS3/CS5
Form design by Dreamweaver CS3/CS5
 
STC Summit 2015 Hypergraphics for visual-first help
STC Summit 2015 Hypergraphics for visual-first helpSTC Summit 2015 Hypergraphics for visual-first help
STC Summit 2015 Hypergraphics for visual-first help
 
Vaadin Components @ Angular U
Vaadin Components @ Angular UVaadin Components @ Angular U
Vaadin Components @ Angular U
 
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docxsri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
 
Training in Asp.net mvc3 platform-apextgi,noida
Training in Asp.net mvc3 platform-apextgi,noidaTraining in Asp.net mvc3 platform-apextgi,noida
Training in Asp.net mvc3 platform-apextgi,noida
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and html
 
The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180
 
Xaml programming
Xaml programmingXaml programming
Xaml programming
 

Recently uploaded

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Xml

  • 1. <StudentDetails> <Student> <ID>102</ID> <Name>Nimit</Name> <Course>MCA</Course> <College>Abes</College> </Student> </StudentDetails> <body> <form id="form1" runat="server"> <table> <tr> <td> <asp:GridView ID="XmlGridView" runat="server" AutoGenerateColumns="false" Height="247px" Width="795px" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" ShowFooter="true" OnRowCancelingEdit="XmlGridView_RowCancelingEdit" OnRowDeleting="XmlGridView_RowDeleting" OnRowEditing="XmlGridView_RowEditing" OnRowUpdating="XmlGridView_RowUpdating"> <AlternatingRowStyle BackColor="#DCDCDC" /> <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate> <asp:Label ID="LblStuID" runat="server" Text='< %# Bind("ID") %>'></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="TxtStuID" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <asp:Label ID="LblStuName" runat="server" Text='<%# Bind("Name") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TxtEditStuName" runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="TxtStuName" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Course"> <ItemTemplate> <asp:Label ID="LblStuCourse" runat="server" Text='<%# Bind("Course") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TxtEditStuCourse" runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="TxtStuCourse" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField>
  • 2. <asp:TemplateField HeaderText="College"> <ItemTemplate> <asp:Label ID="LblStuCollege" runat="server" Text='<%# Bind("College") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TxtEditStuCollege" runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="TxtStuCollege" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Operations"> <ItemTemplate> <asp:Button ID="BtnEdit" runat="server" CommandName="Edit" Text="Edit" /> <asp:Button ID="BtnDelete" runat="server" CommandName="Delete" Text="Delete" /> </ItemTemplate> <EditItemTemplate> <asp:Button ID="BthUpdate" runat="server" CommandName="Update" Text="Update" /> <asp:Button ID="BtnCancel" runat="server" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> <FooterTemplate> <asp:Button ID="BtnInsert" runat="server" Text="Insert" OnClick="BtnInsert_Click" /> </FooterTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <RowStyle BackColor="#EEEEEE" ForeColor="Black" /> <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#0000A9" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#000065" /> </asp:GridView> </td> </tr> </table> </form> </body> </html> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack == true) { Get_Xml(); } } void Get_Xml()
  • 3. { DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("~/XMLFile1.xml")); if (ds != null && ds.HasChanges()) { XmlGridView.DataSource = ds; XmlGridView.DataBind(); } else { XmlGridView.DataBind(); } } protected void XmlGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { XmlGridView.EditIndex = -1; Get_Xml(); } protected void XmlGridView_RowEditing(object sender, GridViewEditEventArgs e) { XmlGridView.EditIndex = e.NewEditIndex; Get_Xml(); } protected void XmlGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { Get_Xml(); DataSet ds = XmlGridView.DataSource as DataSet; ds.Tables[0].Rows[XmlGridView.Rows[e.RowIndex].DataItemIndex].Delete(); ds.WriteXml(Server.MapPath("~/MyXmlFile.xml")); Get_Xml(); } protected void XmlGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { int id = XmlGridView.Rows[e.RowIndex].DataItemIndex; TextBox Name = XmlGridView.Rows[e.RowIndex].FindControl("TxtEditStuName") as TextBox; TextBox Course = XmlGridView.Rows[e.RowIndex].FindControl("TxtEditStuCourse") as TextBox; TextBox College = XmlGridView.Rows[e.RowIndex].FindControl("TxtEditStuCollege") as TextBox; XmlGridView.EditIndex = -1; Get_Xml(); DataSet ds = XmlGridView.DataSource as DataSet; ds.Tables[0].Rows[id]["Name"] = Name.Text; ds.Tables[0].Rows[id]["Course"] = Course.Text; ds.Tables[0].Rows[id]["College"] = College.Text; ds.WriteXml(Server.MapPath("~/MyXmlFile.xml")); Get_Xml(); }
  • 4. protected void BtnInsert_Click(object sender, EventArgs e) { Insert_XML(); } void Insert_XML() { TextBox Stu_Id = XmlGridView.FooterRow.FindControl("TxtStuID") as TextBox; TextBox Stu_Name = XmlGridView.FooterRow.FindControl("TxtStuName") as TextBox; TextBox Stu_Course = XmlGridView.FooterRow.FindControl("TxtStuCourse") as TextBox; TextBox Stu_College = XmlGridView.FooterRow.FindControl("TxtStuCollege") as TextBox; XmlDocument MyXmlDocument = new XmlDocument(); MyXmlDocument.Load(Server.MapPath("~/MyXmlFile.xml")); XmlElement ParentElement = MyXmlDocument.CreateElement("Student"); XmlElement ID = MyXmlDocument.CreateElement("ID"); ID.InnerText = Stu_Id.Text; XmlElement Name = MyXmlDocument.CreateElement("Name"); Name.InnerText = Stu_Name.Text; XmlElement Course = MyXmlDocument.CreateElement("Course"); Course.InnerText = Stu_Course.Text; XmlElement College = MyXmlDocument.CreateElement("College"); College.InnerText = Stu_College.Text; ParentElement.AppendChild(ID); ParentElement.AppendChild(Name); ParentElement.AppendChild(Course); ParentElement.AppendChild(College); MyXmlDocument.DocumentElement.AppendChild(ParentElement); MyXmlDocument.Save(Server.MapPath("~/MyXmlFile.xml")); Get_Xml(); }