How to sort a gridview once a radio button is selected
我正在尝试在选择单选按钮后立即在 gridview 中对记录进行排序。我的方法是使用数据视图,但由于数据集变量无法在往返服务器的过程中幸存下来,我不知道如何实现这一点。请帮忙!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | Public Sub GetCustomers() db.RunProcedure("usp_customers_get_all") db.doSort(radList.SelectedValue) gvCustomers.DataSource = db.MyView END Sub Protected Sub radList_SelectedIndexChanged(ByVal sender AS Object, ByVal e AS System.EventArgs) Handles radList.SelectedIndexChanged IF radList.SelectedValue = 0 THEN db.doSort(0) gvCustomers.DataSource = db.MyView END IF IF radList.SelectedValue = 1 THEN db.doSort(1) gvCustomers.DataSource = db.MyView END IF END Sub Public Sub doSort(ByVal strIn AS INTEGER) IF strIn = 0 THEN MyView.Sort ="lastname, firstname" ELSE MyView.Sort ="username" END IF END Sub Public Sub RunProcedure(ByVal strName AS String) Dim objConnection AS NEW SqlConnection(mstrConnection) Dim mdbDataAdapter AS NEW SqlDataAdapter(strName, objConnection) Try mdbDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure Me.mDataset.Clear() mdbDataAdapter.Fill(mDataset,"tblCustomers") MyView.Table = mDataset.Tables("tblCustomers") Catch ex AS Exception Throw NEW Exception("stored procedure is" & strName.ToString &" error is" & ex.Message) END Try END Sub |
您可以将数据集存储在以下位置之一,然后在回发发生时从那里再次加载它。我在公司内部网上做过很多这样的事情。
我真的无法提供更多帮助,因为您没有指定这是在 Ajax 中完成还是进行完整回发等。如果您提供更多信息,我很乐意为您提供帮助。