Click here to Skip to main content
15,889,391 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Listview controls like this

ASP.NET
<asp:ListView ID="categoryList" ItemType="CodeCamper.EntityLayer.Transaction.FavoriteVO" DataKeyNames="FavoriteID" GroupItemCount="1" SelectMethod="GetCategories" runat="server">                      
</asp:ListView>


and in the code behind I'm setting the SelectMethod property

C#
categoryList.SelectMethod = "GetbyTime"


Now if I want to call a parameterized method

C#
public List<FavoriteVO> GetbyTime(string message)
        {
           
        }


How do I have to modify and assign to categoryList.SelectMethod = section ?

What I have tried:

ASP.NET
<asp:ListView ID="categoryList" ItemType="CodeCamper.EntityLayer.Transaction.FavoriteVO" DataKeyNames="FavoriteID" GroupItemCount="1" SelectMethod="GetCategories" runat="server">                      
</asp:ListView>


C#
categoryList.SelectMethod = "GetbyTime"


C#
public List<FavoriteVO> GetbyTime(string message)
        {
           
        }


ASP.NET
<ul class="nav nav-pills nav-stacked">
                      <asp:Repeater ID="SessionVORepeater" runat="server" OnItemCommand="SessionVORepeater_ItemCommand">
                           <ItemTemplate>
                               <li class="active">
                                   <%--<a href="#" runat="server" onserverclick="MyFuncion_Click" CommandName="ViewPDF" ><%# DataBinder.Eval(Container.DataItem, "SessionTimeSlot") %></a>--%>
                                    <asp:Button ID="Button1" class="btn btn-primary" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "SessionTimeSlot") %>' CommandName="ViewDetails" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"SessionTimeSlot") %>' OnClick="MyFuncion_Click"/>
                               </li>
                           </ItemTemplate>
                       </asp:Repeater>
                      <%-- <li class="active"><a href="#">Home</a></li>
                        <li class="active"><a href="#">sfsfs</a></li>--%>
                   </ul>


C#
protected void MyFuncion_Click(object sender, EventArgs e)
        {
             Button btn = (Button) sender;
             RepeaterItem item = (RepeaterItem) btn.NamingContainer;
             Button btnNewNumber0 = (Button)item.FindControl("Button1");
             System.Web.HttpContext.Current.Response.Write("");

             categoryList.SelectMethod = "GetbyTime";
        }
Posted
Updated 28-Sep-16 9:44am
v10
Comments
Karthik_Mahalingam 29-Sep-16 1:12am    
try hardcoding some value and check

1 solution

It looks like you were using Model Bindings. According to the documentation here: Exercise 1: Model Binding in ASP.NET Web Forms[^]

On the method parameter, you can use value provider attributes to specify the value’s data source. For example:

Controls on the page
Query string values
View data
Session state
Cookies
Posted form data
View state
Custom value providers are supported as well

So for example you want pass a parameter to your Select Method to filter the result based from a control value, you can do something like:

C#
public List<favoritevo> GetbyTime([Control]string TextBox1)
{
            //your code logic here
}
 
Share this answer
 
v2
Comments
[no name] 28-Sep-16 15:46pm    
I have updated my original code , please refer that , but still GetbyTime([System.Web.ModelBinding.Control("Button")] string message){} string message is null
Vincent Maverick Durano 29-Sep-16 3:32am    
as far as I know, you need to use the control ID as the parameter name when using Control as the value provider. Please read the docs carefully.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900