Solved

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

Posted on 2004-08-10
1
355 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
ID: 11764252
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 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