?
Solved

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

Posted on 2004-08-10
1
Medium Priority
?
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
AerosSaga earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 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