关闭

DataList专题

825人阅读 评论(0) 收藏 举报

ASPX部分:其中模版列有两个控件,分别为ImageButton,和LinkButton。 
----------------------------------------------------------------------------------------------------------------------
 <asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333" RepeatColumns="1" Width="88px">
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <SelectedItemStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True" />
                        <ItemTemplate>
                            <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Selec"
                                ImageUrl="~/Images/BaseImages/info.jpg" />
                            <asp:LinkButton ID="LinkButton1" runat="server"  Text='<%# DataBinder.Eval(Container.DataItem,"RoomName") %>' CommandName="Selec" CausesValidation="False"></asp:LinkButton>
                        </ItemTemplate>
                        <AlternatingItemStyle BackColor="White" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <ItemStyle BackColor="#EFF3FB" />
                    </asp:DataList>

为DataList指定数据源:.vb文件。
----------------------------------------------------------------------------------------------------------------------
    Private Sub BindDL()
        DataList1.DataSource = met.getAllMeetingRooms(Session("GLOBAL_DepCode").ToString())
        DataList1.DataKeyField = "Bid"
        DataList1.DataBind()
    End Sub


为模版列添加事件:.vb文件
----------------------------------------------------------------------------------------------------------------------
方法1:利用ItemCommand事件。需要指定其中控件(例如)的CommandName,推荐,并且多个控件可以共用一个CommandName。
Protected Sub DataList1_ItemCommand(ByVal ource As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
        bid = DataList1.DataKeys(e.Item.ItemIndex).ToString
        If e.CommandName = "Selec" Then
            BindGV(bid)
        End If
    End Sub 

方法2:利用LinkButton
    'Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    '    Dim r As Integer
    '    r = CType(CType(sender, LinkButton).NamingContainer, DataListItem).ItemIndex
    '    bid = DataList1.DataKeys(r).ToString()
    '    BindGV(bid)
    'End Sub

注意:
----------------------------------------------------------------------------------------------------------------------
1 模板列中的LinkButton或者别的事件没有触发,请注意页面中是否有验证控件。请将模版列中的控件的 CausesValidation="False"

2

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:168275次
    • 积分:2214
    • 等级:
    • 排名:第17153名
    • 原创:42篇
    • 转载:33篇
    • 译文:0篇
    • 评论:36条
    最新评论