Solved

How do I activate the mouse scroll button event on an asp.net listbox control?

Posted on 2004-08-10
1
352 Views
Last Modified: 2008-02-01
I have an asp.net list box control.  I want to make a mouse scroll button event work with the listbox control.

Please show me the code to make this work...
0
Comment
Question by:seckel
1 Comment
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 total points
Comment Utility
Heres one with rowhighlighting, onclick, & Custom Paging First,Last,Next,Previous

<%@ Page language="vb"  Inherits="DOTNETShoppingCart.PagingDataList" CodeBehind="PagingDataList.aspx.vb" AutoEventWireup="false" %>
<HTML>
      <HEAD>
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            <style>
.GridHeader TD { PADDING-RIGHT: 20px; FONT-WEIGHT: bold; BORDER-BOTTOM: black 2px solid; WHITE-SPACE: nowrap }
.GridItem TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: normal; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; BORDER-BOTTOM: white 1px solid; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #ffffff; asp: Literal id="ItemLetterSpacing" runat="server"></asp:Literal> --> }
.GridItemAlternate TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: normal; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; BORDER-BOTTOM: white 1px solid; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #f3f3f3; asp: Literal id="AltItemLetterSpacing" runat="server"></asp:Literal> --> }
.GridItemOver TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #fffdce }
.GridItemInactive TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: normal; PADDING-BOTTOM: 5px; CURSOR: hand; PADDING-TOP: 5px; BORDER-BOTTOM: white 1px solid; FONT-FAMILY: Courier New; WHITE-SPACE: nowrap; BACKGROUND-COLOR: #d5dbe1; asp: Literal id="InactiveItemLetterSpacing" runat="server"></asp:Literal> --> }
            </style>
            <script language="javascript">
<!--
function openLocation(newlocation) {
      if (newlocation.length != 0)
            window.location = newlocation;
      else
            return;
}
//-->
            </script>
      </HEAD>
      <body>
            <form runat="server">
                  <h3>
                        <H3><asp:datalist id="dtlProducts" runat="server" Width="738px" RepeatColumns="1" DataKeyField="ProductID">
                                    <HeaderTemplate>
                                          <table width="100%" cellspacing="0" cellpadding="0">
                                                <tr class="Gridheader">
                                                      <th align="left" width="15%">
                                                            Image</th>
                                                      <th align="left" width="25%">
                                                            Product Name</th>
                                                      <th align="left" width="45%">
                                                            Description</th>
                                                      <th align="left" width="15%">
                                                            Price</th>
                                                </tr>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                          <tr id="ItemRow" runat="server" class="GridItem" onmouseover="this.className='GridItemOver';"
                                                onmouseout="this.className='GridItem';" onclick='<%# "openLocation(""ProductDetail.aspx?ProductID=" & DataBinder.Eval(Container.DataItem, "ProductID") & """);" %>'>
                                                <td><img src='<%# DataBinder.Eval(Container.DataItem, "ImageSrc", "Pictures/Products/Thumbnails/{0}")%>'></td>
                                                <td><%# DataBinder.Eval(Container.DataItem, "Name") %></td>
                                                <td><%# DataBinder.Eval(Container.DataItem, "Description") %></td>
                                                <td><%# DataBinder.Eval(Container.DataItem, "Price") %></td>
                                          </tr>
                                    </ItemTemplate>
                              </asp:datalist></H3>
                  </h3>
                  <table width="100%">
                        <tr>
                              <td align="left" width="42%"><asp:label id="lblCounts" Runat="server" CssClass="plaintable"></asp:label></td>
                              <TD vAlign="bottom" width="4%"><A id="First" href="pagingdatalist.aspx#BookMark" runat="server" OnServerClick="ShowFirstPage"><IMG src="images/firstpage.gif" border="0"></A>
                              </TD>
                              <TD vAlign="bottom" width="4%"><A id="Previous" href="pagingdatalist.aspx#BookMark" runat="server" OnServerClick="ShowPreviousPage"><IMG src="images/prevpage.gif" border="0"></A>
                              </TD>
                              <TD vAlign="bottom" width="4%"><A id="Next" href="pagingdatalist.aspx#BookMark" runat="server" OnServerClick="ShowNextPage"><IMG src="images/nextpage.gif" border="0"></A>
                              </TD>
                              <TD vAlign="bottom" width="4%"><A id="Last" href="pagingdatalist.aspx#BookMark" runat="server" OnServerClick="ShowLastPage"><IMG src="images/lastpage.gif" border="0"></A>
                              </TD>
                              <TD width="42%">&nbsp;</TD>
                        </tr>
                  </table>
                  <asp:label id="lblRecordCount" Runat="server" Visible="False"></asp:label><asp:label id="lblCurrentIndex" Runat="server" Visible="False" Text="0"></asp:label><asp:label id="lblPageSize" Runat="server" Visible="False" Text="10"></asp:label>
                  <H3>&nbsp;</H3>
            </form>
      </body>
</HTML>

Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration

Public Class PagingDataList : Inherits System.Web.UI.Page

    Protected WithEvents First As System.Web.UI.HtmlControls.HtmlAnchor
    Protected WithEvents Previous As System.Web.UI.HtmlControls.HtmlAnchor
    Protected WithEvents dtlProducts As System.Web.UI.WebControls.DataList
    Protected WithEvents lblCounts As System.Web.UI.WebControls.Label
    Protected WithEvents lblRecordCount As System.Web.UI.WebControls.Label
    Protected WithEvents lblCurrentIndex As System.Web.UI.WebControls.Label
    Protected WithEvents lblPageSize As System.Web.UI.WebControls.Label
    Protected WithEvents Last As System.Web.UI.HtmlControls.HtmlAnchor

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack() Then
            BindTheData()
        End If
    End Sub

    Private Sub BindTheData()
        Dim cnn As New OleDb.OleDbConnection(ConfigurationSettings.AppSettings("SiteDB"))
        Dim DataAdapter As New OleDb.OleDbDataAdapter("SELECT * FROM Products", cnn)
        Dim DataSet As New DataSet
        Dim PageSize As Integer = 10
        cnn.Open()
        If Not Page.IsPostBack() Then
            DataAdapter.Fill(DataSet)
            lblRecordCount.Text = CStr(DataSet.Tables(0).Rows.Count)
            DataSet = Nothing
            DataSet = New DataSet
        End If
        DataAdapter.Fill(DataSet, CInt(lblCurrentIndex.Text), CInt(lblPageSize.Text), "Products")
        dtlProducts.DataSource = DataSet.Tables("Products").DefaultView
        dtlProducts.DataBind()
        cnn.Close()
        ShowCounts()
        cnn.Dispose()
        DataAdapter.Dispose()
    End Sub

    Public Sub ShowFirstPage(ByVal s As System.Object, ByVal e As System.EventArgs)
        lblCurrentIndex.Text = "0"
        BindTheData()
    End Sub

    Public Sub ShowPreviousPage(ByVal s As System.Object, ByVal e As System.EventArgs)
        lblCurrentIndex.Text = CStr(CInt(lblCurrentIndex.Text) - CInt(lblPageSize.Text))
        If CInt(lblCurrentIndex.Text) < 0 Then
            lblCurrentIndex.Text = "0"
        End If
        BindTheData()
    End Sub

    Public Sub ShowNextPage(ByVal s As System.Object, ByVal e As System.EventArgs)
        If CInt(CInt(lblCurrentIndex.Text) + CInt(lblPageSize.Text)) < CInt(lblRecordCount.Text) Then
            lblCurrentIndex.Text = CStr(CInt(lblCurrentIndex.Text) + CInt(lblPageSize.Text))
        End If
        BindTheData()
    End Sub

    Public Sub ShowLastPage(ByVal s As System.Object, ByVal e As System.EventArgs)
        Dim intMod As Integer
        intMod = CInt(lblRecordCount.Text) Mod CInt(lblPageSize.Text)
        If intMod > 0 Then
            lblCurrentIndex.Text = CStr(CInt(lblRecordCount.Text) - intMod)
        Else
            lblCurrentIndex.Text = CStr(CInt(lblRecordCount.Text) - CInt(lblPageSize.Text))
        End If
        BindTheData()
    End Sub

    Private Sub ShowCounts()
        lblCounts.Text = "|Total Rows: <b>" & lblRecordCount.Text
        lblCounts.Text += "</b> | Page:<b> "
        lblCounts.Text += CStr(CInt(CInt(lblCurrentIndex.Text) / CInt(lblPageSize.Text) + 1))
        lblCounts.Text += "</b> of <b>"
        If (CInt(lblRecordCount.Text) Mod CInt(lblPageSize.Text)) > 0 Then
            lblCounts.Text += CStr(CInt(CInt(lblRecordCount.Text) / CInt(lblPageSize.Text) + 1))
        Else
            lblCounts.Text += CStr(CInt(lblRecordCount.Text) / CInt(lblPageSize.Text))
        End If
        lblCounts.Text += "</b> |"
    End Sub
    Private Sub InitializeComponent()

    End Sub
   
    Private Sub dtlProducts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dtlProducts.ItemDataBound
        Dim TR As HtmlTableRow
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            TR = CType(e.Item.FindControl("ItemRow"), Web.UI.HtmlControls.HtmlTableRow)
            If e.Item.ItemType = ListItemType.AlternatingItem Then
                TR.Attributes("onmouseout") = "this.className='GridItemAlternate';"
                TR.Attributes("class") = "GridItemAlternate"
            End If
            If CStr(DataBinder.Eval(e.Item.DataItem, "ProductID")) = "0" Then
                TR.Attributes("class") = "GridItemInactive"
                TR.Attributes("onmouseout") = "this.className='GridItemInactive';"
            End If
        End If
    End Sub

    Private Sub dtlProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtlProducts.SelectedIndexChanged

    End Sub
End Class

Regards,

Aeros
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now