如何在下拉列表选择中获取listview中的记录 [英] how to get records in listview on dropdown selection

查看:48
本文介绍了如何在下拉列表选择中获取listview中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人告诉我如何在下拉列表选项中获取listview中的记录,其中下拉列表都是数据绑定到sqldatasource。并且在选择下拉列表时,我需要在listview中显示记录列表,以便我可以使用gridview

解决方案

将这些记录绑定,以便根据所选的下拉列表显示记录您需要这样做的索引....





1)将选定的索引更改事件附加到您的下拉列表中...



2)编写一个方法或函数来从数据库中选择记录,其中的原因是过滤结果数据...选择这样的查询....

  SELECT  *  FROM  PRODUCT  WHERE  PRODUCT_ID =  @ PRODUCTID  





3)然后调用你内部的函数下拉选择的索引更改事件并传递一个你要传递给select查询参数的值...这里我使用productID作为下拉数据值字段和产品名称作为drop dow n数据文本提交...所以我的代码是这样的...



  protected   void  ddl_SelectedIndexChanged( object  sender,EventArgs e)
{
int productid = Convert.ToInt32(ddlReportSelection.SelectedValue.ToString());
loadDataToListBox(productid);
}
private void loadDataToListBox( int productid)
{
string query = < span class =code-string> SELECT * FROM PRODUCT WHERE PRODUCTID = @PRODUCTID;
/// 填充数据表或数据集的代码在这里....
///
lstview.DataSource = ds;
lstview.DataBind();
}





i希望它能解决你的问题....


检查这个



http://forums.asp .net / t / 1306363.aspx / 1/10 [ ^ ]


 <   asp:SqlDataSource     ID   =  SqlDataSource1    runat   =  server    ConnectionString   =  < ;% 

please any one let me know how can i get records in listview on dropdown selection where both the dropdownlist is databound to sqldatasource. and on selection of dropdown i need to display the list of records in listview so that i can bind this records with gridview

解决方案

Fro displaying Record on the basis of dropdown selected index you need to do like this....


1) Attach a selected index change event to your drop down...

2) write a method or function fro selecting records from database with a where cause to filter resulted data... select query like this....

SELECT * FROM PRODUCT WHERE PRODUCT_ID = @PRODUCTID



3) then call that function inside you dropdown selected index change event and pass a value which you want to pass for select query parameter... here i use a productID as a dropdown data value filed and product name as drop down data text filed... so my code like this...

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    int productid = Convert.ToInt32(ddlReportSelection.SelectedValue.ToString());
    loadDataToListBox(productid);
}       
private void loadDataToListBox(int productid)
{
    string query = "SELECT * FROM PRODUCT WHERE PRODUCTID = @PRODUCTID";
    ///code for fill data table or data set goes here....
    ///
    lstview.DataSource = ds;
    lstview.DataBind();
}



i hope it will solve your problem....


Check this

http://forums.asp.net/t/1306363.aspx/1/10[^]


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


这篇关于如何在下拉列表选择中获取listview中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆