0

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.

4

2 回答 2

2

试试吧,希望对你有用

<asp:TemplateField HeaderText="Name">
        <ItemTemplate>
            <%# Eval("FirstName") + ' ' + Eval("Middle")+ ' ' + Eval("LastName")%>
        </ItemTemplate>
    </asp:TemplateField>
于 2013-11-14T06:32:39.673 回答
0

哦,我明白了..

    <asp:TemplateField HeaderText="Fullname">
    <ItemTemplate>
    <asp:Label ID="Fullname" runat="server" Text='<%#Eval("Lname")+ ", " + Eval("Fname") + " " + Eval("Mname") + "." %>' ></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
于 2013-11-14T04:58:03.443 回答