c# 将两个表的有效数据合到一个表中
<asp:DropDownList ID="ddlSpecialty" runat="server" > </asp:DropDownList>
DataTable dt2 ; DataTable dt1 ; DataTable newDt = new DataTable(); newDt.Columns.Add("Name", typeof(string)); newDt.Columns.Add("Code", typeof(string)); foreach (DataRow dr in dt1.Rows) { var dataRow = newDt.NewRow(); dataRow[0] = dr["ItemName"]; dataRow[1] = dr["ItemCode"]; newDt.Rows.Add(dataRow); } foreach (DataRow dr in dt2.Rows) { var dataRow = newDt.NewRow(); dataRow[0] = dr["ItemName"]; dataRow[1] = dr["ItemCode"]; newDt.Rows.Add(dataRow); } this.ddlSpecialty.DataTextField = "Name"; this.ddlSpecialty.DataValueField = "Code"; this.ddlSpecialty.DataSource = newDt; this.ddlSpecialty.DataBind();