SelectedIndexChanged事件完成后的GridView排序 [英] GridView Sorting After Completion Of SelectedIndexChanged Event

查看:67
本文介绍了SelectedIndexChanged事件完成后的GridView排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个``GridView'',我的GridView中的列之一是DropDownList
我在GridView中输入1条记录意味着DropDownValue为1,我输入2条记录意味着DropDownValue为2 ....就像我在GridView中输入``n''no.of Records.
输入记录后,我将下拉列表的值从7更改为2,然后自动将其更改为
2更改为3,3更改为4,4更改为5,5更改为6,6更改为7.
更改DropDownValues之后,我的GridView记录就是这样.

在获取下拉值之前

I Have a ''GridView'' ,one of the Column in My GridView is DropDownList,
I enter 1 Record into GridView means DropDownValue is 1,I enter 2 Record means DropDown Value is 2....like that i enter ''n'' no .of Records into my GridView.
After entering the Records , I''m changing Dropdown value 7 to 2, then Automatically
2 is changed to 3 ,3 is changed to 4, 4 is changed to 5, 5 is changed to 6, 6 is Changed to 7.This is working fine.

After Changing the DropDownValues My GridView Records are like this.

BEFORE CHANING DROPDOWN VALUES

GRIDVIEW



名称排序
A 1
B 2
C 3
D 4
E 5
F 6
G 7



更改下拉值后



Name Sort
A 1
B 2
C 3
D 4
E 5
F 6
G 7



AFTER CHANGING DROPDOWN VALUES

<pre lang="vb">GRIDVIEW</pre>



名称排序
A 2
B 3
C 4
D 5
E 6
F 7
G 1

现在,我的问题是...
更改"DropDownValues"后,我的GridView排序值如下所示:2,3,4,5,6,7,1
现在我又想更改/我的DropDown值意味着它没有得到正确的值.为什么因为GridValues不在排序顺序中,所以在我的代码中我写的是这种类型的代码.更改了Drop值之后(SelectedIndexCahnged事件完成)那我也要这样



NAME SORT
A 2
B 3
C 4
D 5
E 6
F 7
G 1

Now, my question is ...
After Changing ''DropDownValues'' My GridView Sorted Values are like this 2,3,4,5,6,7,1
Now again i want to Change /my DropDown Values means It''s not Getting Correct Values.Why because GridValues are not in Sorted Order, In my Code I wrote like that type of code.After Changing Drop Values (SelectedIndexCahnged Event is completed) then also i want like This

GRIDVIEW




名称排序
G 1
A 2
B 3
C 4
D 5
E 6
F 7

如果我的网格是这样的(在SelectedIndexChanged完成之后),那么我的代码将完美执行,为此我将设置GridView属性" AllowSorting ="True".
但是没有用,请给我任何建议.




Name Sort
G 1
A 2
B 3
C 4
D 5
E 6
F 7

If my Grid like this ( After Completion Of SelectedIndexChanged) then, my Code is executed Perfectly, for that i''m setting GridView Property ''AllowSorting ="True"''.
But no use ,plz give any suggestion to do this.

推荐答案

对于DropDownList的SelectIndexChanged事件,您可能会有类似的内容

You could have something like this in for the DropDownList''s SelectIndexChanged Event

protected void DropDownList1_SelectIndexChanged(object sender, EventArgs e)
{
    gvSorting.Sort(DropDownList1.SelectedValue, SortDirection.Ascending);
}



并处理GridView的Sorting事件



and handle GridView''s Sorting event

protected void gvSorting_Sorting(object sender, GridViewSortEventArgs e)
{
    DataTable dtSortTable = gvSorting.DataSource as DataTable;
    if (dtSortTable != null)
    {
        DataView dvSortedView = new DataView(dtSortTable);
        dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);
        gvSorting.DataSource = dvSortedView;
        gvSorting.DataBind();
    }
}

private static string getSortDirectionString(SortDirection sortDireciton)
{
    string newSortDirection = String.Empty;
    if (sortDireciton == SortDirection.Ascending)
    {
        newSortDirection = "ASC";
    }
    else
    {
        newSortDirection = "DESC";
    }
    return newSortDirection;
}


尝试 [


Try this[^] also.


--Amit


这篇关于SelectedIndexChanged事件完成后的GridView排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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