---
title: "Minimize ds.readxml statment at one place"  
description: "Minimize ds.readxml statment at one place"  
author: "Noopur Kumari"  
published: 2012-02-07  
updated: 2012-02-07  
canonical: https://www.mindstick.com/forum/381/minimize-ds-readxml-statment-at-one-place  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Minimize ds.readxml statment at one place

```
protected void Page_Load(object sender, EventArgs e){DataSet ds = new DataSet();ds.ReadXml(Server.MapPath("emp.xml"));grdEmployee.DataSource = ds.Tables["Employee"];grdEmployee.DataBind();} protected void grdEmployee_RowDataBound(object sender, GridViewRowEventArgs e){if (e.Row.RowType == DataControlRowType.DataRow){DropDownList ddlDepartment = (DropDownList)e.Row.FindControl("ddlDepartment");Label lblid = (Label)e.Row.FindControl("lbldept");DataSet dsr = new DataSet();dsr.ReadXml(Server.MapPath("Dept.xml"));ddlDepartment.DataSource = dsr;//ddlDepartment.DataTextField = "Dname";//ddlDepartment.DataValueField = "Deptid";ddlDepartment.DataBind(); string id = lblid.Text;ddlDepartment.Items.FindByValue(id).Selected = true;ddlDepartment.Items.Insert(0, "-Select Department-"); // ddlDepartment.SelectedValue = e.Row.Cells[0].Text;} }}
```

**[aspx page](https://www.mindstick.com/forum/218/how-do-i-create-an-aspx-page-that-periodically-refreshes-itself):**\
\
![Minimize ds.readxml statment at one place](http://www.codeproject.com/images/minus.gif) Collapse | Copy Code

```
<asp:GridView ID="grdEmployee" runat="server" AutoGenerateColumns="false"
            onrowdatabound="grdEmployee_RowDataBound" Height="273px" Width="455px">
            <Columns>
            <asp:TemplateField>
                    <ItemTemplate>
                       <asp:Label ID="lbldept" runat="server" Text='<%#Bind("deptid") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="ddlDepartment" DataValueField="value" DataTextField="name" runat="server">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="name" HeaderText="name" />
                <asp:BoundField DataField="sal" HeaderText="sal" />
                <asp:BoundField DataField="Deptid" HeaderText="Deptid" ControlStyle-Width="0px" />
            </Columns>
        </asp:GridView>
```

in [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind) i have written two times ds.readxml beacuse one emp.xml is [binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) [grid](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) and another one is binding with drop downlist.how can i place at one place i have two xml files.dept.xml is binding with drop downlist which is inside a [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net).MY [assignment](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) is write to place one place it because no need to write two times ds.readxml.How will be done ?pls [anyone help me](https://www.mindstick.com/forum/331/can-anyone-help-me-out-how-to-use-session-concept)

## Replies

### Reply by James Smith

Hi Noopur,\
You can also use XmlDataSource control for binding record in GridView and combobox. By This way you did not need to bind record multiple times.\
\
Thanks


---

Original Source: https://www.mindstick.com/forum/381/minimize-ds-readxml-statment-at-one-place

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
