基于下拉列表在gridview中计算行数 [英] row counting in gridview based on dropdown

查看:59
本文介绍了基于下拉列表在gridview中计算行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有c组件的下拉列表。



基于我需要d组件进入gridview中的其他下拉列表。



但我得到的总数没有数据库中的行进入gridview。



例如:如果我在数据库中有4个行没有基于c组件的d个组件,则只有2行d组件必须绑定到gridview,但是我将数据库中的总行数添加到gridview。



所以我这个视图任何人帮助我....

解决方案

不确定我是否正确,但我会开枪。听起来你正试图过滤你的数据集。因此,您有一个完整的数据集4,并且您希望根据下拉列表中选择的值添加一些条件,并根据选择限制数据集。因此,您可以处理下拉列表中的SelectedIndexChanged事件,并在该处理程序中为网格设置过滤器。这样的事情:

 私人 MyDataTable  As  字符串 =   mydatatablename 
受保护的 Sub Page_Load( ByVal 发​​件人作为 对象 ByVal e As System.EventArgs)句柄 .Load
使用 dt 作为 DataTable = GetDataTable()
Session(MyDataTable)= dt
GridView1.DataSource = dt
GridView1.DataBind()
结束 使用
结束 Sub

受保护 Sub DropDownList1_SelectedIndexChanged(sender As Object ,e As EventArgs)句柄 DropDownList1.SelectedIndexChanged
使用 dt 作为 DataTable = Session(MyDataTable),
dv As DataView(dt)使用 {.RowFilter = MyKey =& DropDownList1.SelectedValue}
GridView1.DataSource = dv
GridView1.DataBind()
结束 使用
结束 Sub


hi

I had dropdown of c components.

Based on that i need d components into other dropdown in gridview.

but i m getting total no of rows in database into the gridview.

for ex: if i have 4 no of rows in database with 2 no of d components based on c component, only 2 rows of d components must be binded to gridview, but i m getng total rows in database to gridview.

so i this view any one help me....

解决方案

Not sure I'm getting this right, but I'll take a shot. Sounds like you're trying to filter your dataset. So you've got a full dataset of 4, and you want to add some condition based on the value selected in a dropdown, and limit your dataset based on the selection. So you can, for example, handle the SelectedIndexChanged event of your dropdown, and in that handler, set the filter for your grid. Something like this:

Private MyDataTable As String = "mydatatablename"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Using dt As DataTable = GetDataTable()
        Session(MyDataTable) = dt
        GridView1.DataSource = dt
        GridView1.DataBind()
    End Using
End Sub

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
    Using dt As DataTable = Session(MyDataTable),
        dv As New DataView(dt) With {.RowFilter = "MyKey = " & DropDownList1.SelectedValue}
        GridView1.DataSource = dv
        GridView1.DataBind()
    End Using
End Sub


这篇关于基于下拉列表在gridview中计算行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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