Asp:listview使用带参数的方法设置selectmethod [英] Asp:listview set selectmethod with a method having parameter
本文介绍了Asp:listview使用带参数的方法设置selectmethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的Listview控件
< asp:ListView ID = categoryList ItemType = CodeCamper.EntityLayer.Transaction.FavoriteVO DataKeyNames = FavoriteID GroupItemCount = 1 SelectMethod = GetCategories runat = server >
< / asp:ListView >
和后面的代码我正在设置SelectMethod属性
categoryList.SelectMethod = GetbyTime
现在,如果我想调用参数化方法
public 列表< FavoriteVO> GetbyTime( string 消息)
{
}
我如何修改并分配到categoryList.SelectMethod =部分?
我尝试过: < br $> b $ b
< asp:ListView ID = categoryList ItemType = CodeCamper.EntityLayer.Transaction.FavoriteVO DataKeyNames = FavoriteID GroupItemCount = 1 SelectMethod = GetCategories runat = 服务器 >
< / asp:ListView >
< pre lang =c#> categoryList.SelectMethod = GetbyTime
< br $> b $ b
public 列表< FavoriteVO> GetbyTime( string 消息)
{
}
< ul class = nav nav-pills nav-stacked >
< asp:Repeater ID = SessionVORepeater runat = server OnItemCommand = SessionVORepeater_ItemCommand >
< ItemTemplate >
< li class = 有效 >
<% - < a href =#runat =serveronserverclick =MyFuncion_ClickCommandName =ViewPDF><%#DataBinder.Eval(Container.DataItem,SessionTimeSlot)%>< / a> - - %>
< ; asp:按钮 ID = Button1 class = btn btn-primary runat = server 文字 =' <%#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 = # >家庭和LT; / A>< /锂>
< li class =active>< a href =#> sfsfs< / a>< / li> - %>
< / ul >
protected void MyFuncion_Click( object sender,EventArgs e)
{
Button btn =(Button)sender;
RepeaterItem item =(RepeaterItem)btn.NamingContainer;
按钮btnNewNumber0 =(按钮)item.FindControl( Button1);
System.Web.HttpContext.Current.Response.Write( );
categoryList.SelectMethod = GetbyTime;
}
解决方案
看起来你正在使用Model Bindings。根据此处的文档:练习1:ASP.NET Web窗体中的模型绑定 [ ^ ]
在method参数上,您可以使用值提供程序属性来指定值的数据源。例如:
页面控件
查询字符串值
查看数据
会话状态
Cookies
发布表格数据
查看状态
支持自定义价值提供商
因此,例如,您希望将参数传递给Select Method以根据控件值过滤结果,您可以执行以下操作:
public 列表< favoritevo> GetbyTime([Control] string TextBox1)
{
// 您的代码逻辑
}
I have a Listview controls like this
<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
categoryList.SelectMethod = "GetbyTime"
Now if I want to call a parameterized method
public List<FavoriteVO> GetbyTime(string message)
{
}
How do I have to modify and assign to categoryList.SelectMethod = section ?
What I have tried:
<asp:ListView ID="categoryList" ItemType="CodeCamper.EntityLayer.Transaction.FavoriteVO" DataKeyNames="FavoriteID" GroupItemCount="1" SelectMethod="GetCategories" runat="server">
</asp:ListView>
categoryList.SelectMethod = "GetbyTime"
public List<FavoriteVO> GetbyTime(string message)
{
}
<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>
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";
}
解决方案
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:
public List<favoritevo> GetbyTime([Control]string TextBox1) { //your code logic here }
这篇关于Asp:listview使用带参数的方法设置selectmethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文