We help IT Professionals succeed at work.
Get Started

Vb.net: Datalist - Change objectdatasource select method depending on control

767 Views
Last Modified: 2012-05-09
As shown in the code below, I have a datalist which gets its data from the objectDatasource - ObjectDataSource.

I also have tow link buttons and one repeater which is populated with Alpahets having the following click events it he code behind.

At the moment the datalist displayes data is linked to selectmethod SelectMethod="BindData".  I want to now change the behaviour of the datalist and datasource so that depending on the selection(click) of the linkbuttons or the repeater alpahets, i want to load the datalist with different data.

I have 3 different stored procs which get the required data. My problem is how do i link the click event of the link buttons or the alphbet repeater so that the relevant data is shown by the datalist.
<table cellpadding="0" cellspacing="0" border="0" align="center">
                                                <tr>
                                                    <td align="center">
                                                        <asp:LinkButton ID="lnkLastestEntries" runat="server" Text="50 Latest Entries" OnClick="LastestEntries_Click"
                                                            Enabled="true" />
                                                        |
                                                        <asp:LinkButton ID="lnkMostViewed" runat="server" Text="50 Most Viewed" OnClick="MostViewed_Click"
                                                            Enabled="true" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="center">
                                                        <asp:Repeater ID="rptAlphabets" runat="server">
                                                            <ItemTemplate>
                                                                <asp:LinkButton ID="lnkAlphabet" runat="server" Text='<%#Eval("Value")%>' OnClick="Alphabet_Click"
                                                                    Enabled='<%# Eval("isNotSelected")%>' />
                                                            </ItemTemplate>
                                                        </asp:Repeater>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div style="position: relative; height: 545px; width: 420px; overflow: auto;">
                                                            <asp:DataList ID="dlContacts" runat="server" RepeatLayout="Table" RepeatColumns="1" dataSourceID="SDataSource" 

                                                                CellPadding="2" CellSpacing="2">
                                                                <ItemTemplate>
                                                                    <table cellpadding="2" cellspacing="0" border="0" style="width: 390px; border: solid 1px #D2E4FC;">
                                                                        <tr>
                                                                            <td rowspan="4" width="25%">
                                                                                <a href="?id=<%#Eval("pid")%>">
                                                                                    
                                                                        <tr>
                                                                            <td>
                                                                                
                                                                                    <%#Eval("eline")%></a></b>
                                                                            </td>
                                                                        </tr>
                                                                        <tr>
                                                                            <td>
                                                                                Viewer:
                                                                                <%#Eval("likerdata")%>
                                                                                                   </td>
                                                                        </tr>
                                                                    </table>
                                                                </ItemTemplate>
                                                            </asp:DataList>
                                                               <div id="paging" align="center">
                    <asp:Label ID="lblPagerLocation" runat="server" />  
                    <asp:PlaceHolder ID="ViewAll" runat="server"></asp:PlaceHolder>
                    <a id="PrevPage" runat="server">
                        <asp:Image runat="Server" id="PrevImage"  src="http://myserver.com/static/images/previous.gif"
                              AlternateText="Previous page" /></a>
                    <asp:PlaceHolder ID="PageLinks" runat="server"></asp:PlaceHolder>
                    <a id="NextPage" runat="server">
                       <tz:Img runat="Server" id="NextImage" src="http://myserver.com/static/images/next.gif"
                           AlternateText="Next page" skinid="nextpage"/></a>
                </div>            
        
    </div>    
    <asp:ObjectDataSource ID="SDataSource"  TypeName="entries.Index" 
          Runat="server"      SelectMethod="BindData">
        <SelectParameters>
               <asp:QueryStringParameter Name="PageIndex" 
                 QueryStringField="PageIndex" DefaultValue="0" />
            <asp:QueryStringParameter Name="NumRows" 
                 QueryStringField="NumRows" DefaultValue="3" />
            <asp:Parameter Name="Count" 
                 Direction="Output" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE