locked
How can get only one id to Repeater Control from xml file RRS feed

  • Question

  • User942195704 posted

    Hi,

    I have xml file like ,

    <Employees>
      <employee id ="1" name="emp1"  designation="Managing Director" company="comp1"/>
      <employee id ="2" name="emp2"  designation=""Team Leader (S/W)"" company=""comp2""/>

    <employee id ="3" name="emp3"  designation="Managing Director" company="comp1"/

    </Employees>

    I bind the xml value in to the Repeater control it displaying all the employee but i need to display the only one employee how can i do this.

    Please help me .

    Wednesday, July 15, 2015 3:26 AM

Answers

  • User61956409 posted

    Hi Rajamanikkam Jesus,

    Welcome to ASP.NET forum.

    I bind the xml value in to the Repeater control it displaying all the employee but i need to display the only one employee how can i do this.

    Please refer to the following sample.

    <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
            <table>
                <tr>
                    <td>Id</td>
                    <td>Name</td>
                    <td>Designation</td>
                    <td>Company</td>
                </tr>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label ID="lblid" runat="server" Text='<%#Eval("id") %>'></asp:Label></td>
                <td>
                    <asp:Label ID="lblname" runat="server" Text='<%#Eval("name") %>'></asp:Label></td>
                <td>
                    <asp:Label ID="lbldes" runat="server" Text='<%#Eval("designation") %>'></asp:Label></td>
                <td>
                    <asp:Label ID="lblcom" runat="server" Text='<%#Eval("company") %>'></asp:Label></td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater> 
    
    protected void Page_Load(object sender, EventArgs e)
    {
        using (DataSet ds = new DataSet())
        {
            ds.ReadXml(Server.MapPath("Data/EmployeesTab.xml"));
    
            DataView dv = new DataView(ds.Tables[0]);
            dv.RowFilter = "id=1";
    
            Repeater1.DataSource = dv;
            Repeater1.DataBind();
        }
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2015 1:48 AM

All replies

  • User61956409 posted

    Hi Rajamanikkam Jesus,

    Welcome to ASP.NET forum.

    I bind the xml value in to the Repeater control it displaying all the employee but i need to display the only one employee how can i do this.

    Please refer to the following sample.

    <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
            <table>
                <tr>
                    <td>Id</td>
                    <td>Name</td>
                    <td>Designation</td>
                    <td>Company</td>
                </tr>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label ID="lblid" runat="server" Text='<%#Eval("id") %>'></asp:Label></td>
                <td>
                    <asp:Label ID="lblname" runat="server" Text='<%#Eval("name") %>'></asp:Label></td>
                <td>
                    <asp:Label ID="lbldes" runat="server" Text='<%#Eval("designation") %>'></asp:Label></td>
                <td>
                    <asp:Label ID="lblcom" runat="server" Text='<%#Eval("company") %>'></asp:Label></td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater> 
    
    protected void Page_Load(object sender, EventArgs e)
    {
        using (DataSet ds = new DataSet())
        {
            ds.ReadXml(Server.MapPath("Data/EmployeesTab.xml"));
    
            DataView dv = new DataView(ds.Tables[0]);
            dv.RowFilter = "id=1";
    
            Repeater1.DataSource = dv;
            Repeater1.DataBind();
        }
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2015 1:48 AM
  • User942195704 posted

    Thank you Fei Han...

    Thursday, July 16, 2015 5:08 AM