Home > DeveloperSection > Forums > Minimize ds.readxml statment at one place
Noopur Kumari
Noopur Kumari

Total Post:1

Posted on    February-07-2012 6:34 AM

 C# C# 

 1 Reply(s)
 1539  View(s)
Rate this:
protected void Page_Load(object sender, EventArgs e)
DataSet ds = new DataSet();
grdEmployee.DataSource = ds.Tables["Employee"];
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();
ddlDepartment.DataSource = dsr;

//ddlDepartment.DataTextField = "Dname";
//ddlDepartment.DataValueField = "Deptid";
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:
<asp:GridView ID="grdEmployee" runat="server" AutoGenerateColumns="false"
            onrowdatabound="grdEmployee_RowDataBound" Height="273px" Width="455px">
                       <asp:Label ID="lbldept" runat="server" Text='<%#Bind("deptid") %>'></asp:Label>
                        <asp:DropDownList ID="ddlDepartment" DataValueField="value" DataTextField="name" runat="server">
                <asp:BoundField DataField="name" HeaderText="name" />
                <asp:BoundField DataField="sal" HeaderText="sal" />
                <asp:BoundField DataField="Deptid" HeaderText="Deptid" ControlStyle-Width="0px" />
in code behind i have written two times ds.readxml beacuse one emp.xml is binding 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.MY 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

James Smith

Total Post:48

Posted on    February-07-2012 7:11 AM

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.


Don't want to miss updates? Please click the below button!

Follow MindStick