获取动态数据,在asp.net的aspx页面上显示

本文关键字:aspx 显示 net 数据 动态 asp 获取 | 更新日期: 2023-09-27 18:07:10

我使用下面的代码来显示一个用户的个人资料信息,但是你可以看到它的静态数据,因此我必须为每个人单独创建一些页面。

                <td valign="top" class="main_text" >
                    <h1>Attendance Dashboard</h1>
                        <table cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr>
                                <td></br></br>
                                    <table cellspacing="0" cellpadding="0" border="0" width="100%">
                                        <tr>
                                            <td>
                                                <h3 style="display:inline;">Name:</h3> <h4 style="display:inline;" >Usman Abdullah</h4>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <h3 style="display:inline;">Gender:</h3> <h4 style="display:inline;" >Male</h4>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <h3 style="display:inline;">Department:</h3> <h4 style="display:inline;" >BS Computer Science</h4>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td >
                                                <h3 style="display:inline;">Designation:</h3> <h4 style="display:inline;" >Student</h4>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <h3 style="display:inline;">Number:</h3> <h4 style="display:inline;" >0333-1234567</h4>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="400px" align="center">
                                <BR/><BR/>
                                    <img src="css/images/profile_pic.jpg">
                                </td>
                            </tr>

是否可以指定一种方法,以便我可以在访问特定用户的配置文件时直接从数据库插入这些值?

获取动态数据,在asp.net的aspx页面上显示

代替

<h3 style="display:inline;">Name:</h3> <h4 style="display:inline;" >Usman Abdullah</h4>

这样做

<h3 style="display:inline;">Name:</h3> <h4 style="display:inline;" ><asp:Literal ID="lblName" runat="server" /></h4>
并通过

后面的代码填充数据
            /*
             *  When you access an user profile like www.yoursite.com/user.aspx?userId=3
             *  You must get the parameter "userId=3" and search in database for the user with ID = 3
             *  and return an object with its data
             */
            User user = GetUserFromDatabase(Int32.Parse(Request["userId"]));
            /*
             * And put dynamically in the page like 
             */
            lblName.Text = user.Name;
            lblDepartment.Text = user.Department;
            //and go on..