前台页面放置GridView,DataList和ListBox控件

GridView, DataList and ListBox 行 单击与双击事件处理

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

<!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">
    
<h2> GridView, DataList and ListBox单击与双击事件</h2>
    
<div>        
        
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#DEDFDE" 
            BorderStyle
="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" 
            OnRowDataBound
="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand">
            
<FooterStyle BackColor="#CCCC99" />
            
<Columns>                
                
<asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="false"/>
                
<asp:ButtonField Text="DoubleClick" CommandName="DoubleClick" Visible="false"/>
            
</Columns>
            
<RowStyle BackColor="#F7F7DE" />
            
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />            
            
<AlternatingRowStyle BackColor="White" />
        
</asp:GridView>
        
<br /><br />
        
<asp:DataList ID="DataList1" runat="server" width="400px"
        OnItemCommand
="DataList1_ItemCommand" OnItemDataBound="DataList1_ItemDataBound">
            
<HeaderTemplate>
                任务列表
            
</HeaderTemplate>
            
<ItemTemplate>
                
<asp:LinkButton ID="LinkButton1" runat="server" Text="SingleClick" CommandName="SingleClick" Visible="false"/>
                
<asp:LinkButton ID="LinkButton2" runat="server" Text="DoubleClick" CommandName="DoubleClick" Visible="false"/>
                
<asp:Panel ID="Panel1" runat="server">
                    
<span style="float:left;">
                        
<b>编号: </b><%# Eval("Id"%>
                        
&nbsp;&nbsp;<b>任务: </b><%# Eval("Task"%>
                    
</span>
                    
<span style="float:right;">
                        
<b>是否完成: </b><%# Eval("IsDone"%>
                    
</span>
                
</asp:Panel>
            
</ItemTemplate> 
            
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />    
            
<ItemStyle BackColor="#F7F7DE" BorderStyle="Solid" BorderColor="lightgray" BorderWidth="1px" />
            
<AlternatingItemStyle BackColor="white" />
            
<SelectedItemStyle BackColor="#CE5D5A" /> 
        
</asp:DataList>
        
<br /><br />
        
<asp:ListBox ID="ListBox1" runat="server" DataTextField="Task" DataValueField="Id" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"></asp:ListBox>
        
<br /><br />
        
<asp:Label id="Message" runat="server" ForeColor="Red" Font-Bold="true"></asp:Label>        
     
</div>
    
</form>
</body>
</html>

相关文章: