用于检索记录和显示表的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
。
答案 0 :(得分:2)
请尝试IT,我希望它对您有用
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# Eval("FirstName") + ' ' + Eval("Middle")+ ' ' + Eval("LastName")%>
</ItemTemplate>
</asp:TemplateField>
答案 1 :(得分:0)
哦,我明白了..
<asp:TemplateField HeaderText="Fullname">
<ItemTemplate>
<asp:Label ID="Fullname" runat="server" Text='<%#Eval("Lname")+ ", " + Eval("Fname") + " " + Eval("Mname") + "." %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>