asp.net之listview学习笔记_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > asp.net之listview学习笔记

asp.net之listview学习笔记

 2012/3/15 11:23:41  xiaofancn  程序员俱乐部  我要评论(0)
  • 摘要:通过vs的页面设置把页面的功能设置出来,(分页功能需要数据源的类型为IEnumerable),然后把数据源删除,该成手工精确赋值。大致有编辑,删除,取消,插入。通过vs生成事件代码//更新事件代码protectedvoidListView1_ItemUpdating(objectsender,ListViewUpdateEventArgse){//主要是获取页面对应的控件,再获取数据LabeluidLabel1=(Label)ListView1.Items[e.ItemIndex]
  • 标签:笔记 .net ASP.NET 学习 view list net 学习笔记

?

通过vs的页面设置把页面的功能设置出来,(分页功能需要数据源的类型为IEnumerable),然后把数据源删除,该成手工精确赋值。
大致有编辑,删除,取消,插入。
通过vs生成事件代码

?

//更新事件代码
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {//主要是获取页面对应的控件,再获取数据
            Label uidLabel1 = (Label)ListView1.Items[e.ItemIndex].FindControl("uidLabel1");
            //数据处理代码
            ListView1.EditIndex = -1;           
        }

//插入事件代码
protected void ListView1_ItemInserting(object sender, ListViewInsertEventArgs e)
        {还是获取控件,再获取数据
            TextBox usernameTextBox= (TextBox)e.Item.FindControl("usernameTextBox");
            Response.Write(usernameTextBox.Text);
        }

//其他雷同

?

页面代码

<asp:ListView ID="ListView1" runat="server" DataKeyNames="uid"
        InsertItemPosition="LastItem"
        
        
        
        onselectedindexchanging="ListView1_SelectedIndexChanging"
       >
        <ItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="uidLabel" runat="server" Text='<%# Eval("uid") %>' />
                </td>
                <td>
                    <asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
                </td>
                <td>
                    <asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
                </td>
                <td>
                    <asp:Label ID="sexLabel" runat="server" Text='<%# Eval("sex") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="uidLabel" runat="server" Text='<%# Eval("uid") %>' />
                </td>
                <td>
                    <asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
                </td>
                <td>
                    <asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
                </td>
                <td>
                    <asp:Label ID="sexLabel" runat="server" Text='<%# Eval("sex") %>' />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" style="">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert"
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                        Text="Clear" />
                </td>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:TextBox ID="usernameTextBox" runat="server"
                        Text='<%# Bind("username") %>' />
                </td>
                <td>
                    <asp:TextBox ID="passwordTextBox" runat="server"
                        Text='<%# Bind("password") %>' />
                </td>
                <td>
                    <asp:TextBox ID="sexTextBox" runat="server" Text='<%# Bind("sex") %>' />
                </td>
            </tr>
        </InsertItemTemplate>
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="0" style="">
                            <tr runat="server" style="">
                                <th runat="server">
                                </th>
                                <th runat="server">
                                    uid</th>
                                <th runat="server">
                                    username</th>
                                <th runat="server">
                                    password</th>
                                <th runat="server">
                                    sex</th>
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" style="">
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <EditItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update"
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                        Text="Cancel" />
                </td>
                <td>
                    <asp:Label ID="uidLabel1" runat="server" Text='<%# Eval("uid") %>' />
                </td>
                <td>
                    <asp:TextBox ID="usernameTextBox" runat="server"
                        Text='<%# Bind("username") %>' />
                </td>
                <td>
                    <asp:TextBox ID="passwordTextBox" runat="server"
                        Text='<%# Bind("password") %>' />
                </td>
                <td>
                    <asp:TextBox ID="sexTextBox" runat="server" Text='<%# Bind("sex") %>' />
                </td>
            </tr>
        </EditItemTemplate>
        <SelectedItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="uidLabel" runat="server" Text='<%# Eval("uid") %>' />
                </td>
                <td>
                    <asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
                </td>
                <td>
                    <asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
                </td>
                <td>
                    <asp:Label ID="sexLabel" runat="server" Text='<%# Eval("sex") %>' />
                </td>
            </tr>
        </SelectedItemTemplate>
    </asp:ListView>
?
发表评论
用户名: 匿名