Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- populate LINQ to XML to Grdiview
- <?xml version="1.0" ?>
- - <!-- Created @ 9/14/2011 1:16:52 PM
- -->
- - <DoctorList>
- - <Doctor ID="1" Specialist="Dentist">
- <Username>Ahmed</Username>
- <Password>12345</Password>
- </Doctor>
- - <Doctor ID="2" Specialist="oculist">
- <Username>Aya</Username>
- <Password>12345</Password>
- </Doctor>
- - <Doctor ID="3" Specialist="surgery">
- <Username>malak</Username>
- <Password>12345</Password>
- </Doctor>
- </DoctorList>
- IEnumerable<XElement> matches = from Doctor in doc.Descendants("Doctor") where (int)Doctor.Attribute("ID") > 1 select Doctor;
- GridView1.DataSource= matches;
- GridView1.DataBind();
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
- CellPadding="4" HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="White"
- HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True"
- ondatabound="GridView1_DataBound">
- <Columns>
- <asp:BoundField HeaderText="Specialist" DataField="Specialist" />
- <asp:BoundField HeaderText="ID" DataField="ID" ItemStyle-HorizontalAlign="Right" />
- <asp:BoundField HeaderText="Username" DataField="Username" ItemStyle-HorizontalAlign="Right" />
- <asp:BoundField HeaderText="Password" DataField="Password" ItemStyle-HorizontalAlign="Right" />
- </Columns>
- <HeaderStyle HorizontalAlign="Center" BackColor="Blue" Font-Bold="True" ForeColor="White"></HeaderStyle>
- </asp:GridView>
- IEnumerable<XElement> matches =
- from Doctor in doc.Descendants("Doctor")
- where (int)Doctor.Attribute("ID") > 1
- select new {
- Specialist = Doctor.Attribute("Specialist").Value,
- ID = Doctor.Attribute("ID").Value,
- Username = Doctor.Element("Username").Value,
- Password = Doctor.Element("Password").Value
- };
- GridView1.DataSource = matches;
- GridView1.DataBind();
- <DoctorList>
- <Doctor ID="1" Specialist="Dentist" UserName="Ahmed" Password="12345" />
- <Doctor ID="2" Specialist="oculist" Username="Aya" Password="12345" />
- <Doctor ID="3" Specialist="surgery" Username="malak" Password="12345" />
- </DoctorList>
Add Comment
Please, Sign In to add comment