任何人都可以请简要指导我,需要一点指导。下面是我的查询 [英] can anyone please guide me briefly, need little guidance. below is my query

查看:59
本文介绍了任何人都可以请简要指导我,需要一点指导。下面是我的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建网页表单并在网格视图中以相同的形式单击提交按钮而不使用数据库显示数据



create web form and display data in grid view on clicking submit button in same form without using database

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Employeeform.aspx.cs" Inherits="Employeeform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td align="center">
                <h1>
                    Employee Form</h1>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td align="center">
                <table border="0" cellpadding="0" cellspacing="0" width="40%">
                    <tr>
                        <td align="right">
                            <asp:Label ID="EmpNameLb" runat="server" Text="Employee Name"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:TextBox ID="txtempName" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="EmpAddLb" runat="server" Text="Employee address"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:TextBox ID="txtempAdd" runat="server" TextMode="MultiLine"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="genderLb" runat="server" Text="Gender"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
                                <asp:ListItem Value="1">Male</asp:ListItem>
                                <asp:ListItem Value="2">Female</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="QualifnLb" runat="server" Text="Qualifaication"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="138px">
                                <asp:ListItem Value="0">Select</asp:ListItem>
                                <asp:ListItem Value="1">M.Tech</asp:ListItem>
                                <asp:ListItem Value="2">B.Tech</asp:ListItem>
                                <asp:ListItem Value="3">B.Sc</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" colspan="2">
                            <asp:Button ID="submitBtn" runat="server" Text="Submit" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField HeaderText="EmpName" DataField="EmployeeName" />
                        <asp:BoundField HeaderText="EmpAddress" DataField="EmployeeAddress" />
                        <asp:BoundField HeaderText="Gender" DataField="Gender" />
                        <asp:BoundField HeaderText="Qualification" DataField="Qualification" />
                    </Columns>
                </asp:GridView>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

推荐答案

在submitBtn点击事件中,您可以从控件获取值并创建Employee的Object(创建具有一组的用于保存所需字段的属性)

您可以将这些对象存储为会话中的列表。你需要检查你是否已经在会话中添加了项目。如果您在会话中有项目添加新项目并将网格与所有项目绑定。

如果没有会话项你可以创建列表并添加新项目。将新创建的项添加到会话并绑定到网格视图。

页面加载你需要检查请求是否回发。如果没有回发,您可以清除会话值。

你需要尝试自己完成上述任务。
in submitBtn click event you can get the values from controls and create Object of Employee ( create class with set of properties to hold each field you want)
You can store these objects as List in session. you need to check whether you have already added items in session or not. if you have items in session add new item to it and bind the grid with all the items.
if no session items you can create list and add new item to it. add newly created item to session and bind to grid view.
in page load you need to check whether the request is post back or not. if not post back you can clear the session value.
You need to try your self to do above tasks.


这篇关于任何人都可以请简要指导我,需要一点指导。下面是我的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆