ASP.NET―001:GridView绑定List、页面返回值具体实现(2)


        public void DoAddPersons()
        {
            for (int i = 0; i < 20; i++)
            {
                PersonModel model = new PersonModel();


                model.PersonIndex = i + 1;


                model.PersonID = System.Guid.NewGuid().ToString();


                model.PersonName = "测试" + i;


                model.PersonAge = 27 + i;


                model.PersonSex = i % 2 == 0 ? "男" : "女";


                model.PersonSelected = false;


                this.PersonCollect.Add(model);
            }
        }
    }

绑定的页面前端

复制代码 代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChildFrm.aspx.cs" Inherits="ASPNetGridView.Pages.ChildFrm" %>


<!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 runat="server" ms_positioning="GridLayout">
    <form runat="server" method="post">
    <div>
    <asp:GridView runat="server" AutoGenerateColumns="False"
     EnableViewState="false"
    CellPadding="4"  ForeColor="#333333" DataKeyNames="PersonID"
     OnSelectedIndexChanged="Selcted_Click">
     <Columns>
       <asp:CommandField ShowSelectButton="True" /> 
       <asp:BoundField DataField="PersonIndex" HeaderText="序号"/>
       <asp:TemplateField>
       <ItemTemplate>
       <input type="radio" />
       </ItemTemplate>
       </asp:TemplateField>
       <asp:BoundField DataField="PersonName" HeaderText="姓名" />
       <asp:BoundField DataField="PersonAge" HeaderText="年龄" />
       <asp:BoundField DataField="PersonSex" HeaderText="性别" />
     </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

    </asp:GridView>
    </div>
    </form>
</body>
</html>

绑定页面后台

复制代码 代码如下:


 public partial class ChildFrm : System.Web.UI.Page
    {
        private ChildFrmManager dManager = null;


        protected PersonModel selectItem = null;


        protected void Page_Load(object sender, EventArgs e)
        {
            dManager = ChildFrmManager.DoGetInstance();

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzszx.html