Page_Load()
检索记录和显示表的代码。
sConn = new SqlConnection(sStr);
daEmp = new SqlDataAdapter("SELECT * FROM tblEmployee", sConn);
daDep = new SqlDataAdapter("SELECT * FROM tblDepartment", sConn);
dsEmp = new DataSet();
dsDep = new DataSet();
daEmp.Fill(dsEmp, "tblEmployee");
daDep.Fill(dsDep, "tblDepartment");
dsEmp.Tables["tblEmployee"].PrimaryKey = new DataColumn[] { dsEmp.Tables["tblEmployee"].Columns["EmployeeID"] };
dgvEmployee.DataSource = dsEmp.Tables["tblEmployee"];
dgvEmployee.DataBind();
表dgvEmployee的代码:
<asp:GridView ID="dgvEmployee" runat="server" AutoGenerateColumns="False" cssClass="mytable">
<Columns>
<asp:BoundField datafield="EmployeeID" headertext="Employee ID"/>
<asp:BoundField datafield="DeptID" headertext="Deprtment" />
<asp:BoundField datafield="Lname" headertext="Last Name"/>
<asp:Boundfield datafield="Fname" headertext="First Name"/>
<asp:Boundfield datafield="Mname" headertext="Middle Initial"/>
<asp:Boundfield datafield="Address" headertext="Address"/>
<asp:Boundfield datafield="Email" headertext="Email"/>
<asp:Boundfield datafield="Phone" headertext="Phone"/>
<asp:Boundfield datafield="Jobtitle" headertext="Job Title"/>
<asp:Boundfield datafield="Salary" headertext="Salary"/>
</Columns>
</asp:GridView>
如何以这种格式组合三列:Lname, Fname Mname
.