Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP对加密数据进行排序_C#_Asp.net_Sorting_Gridview_Encryption - Fatal编程技术网

C# ASP对加密数据进行排序

C# ASP对加密数据进行排序,c#,asp.net,sorting,gridview,encryption,C#,Asp.net,Sorting,Gridview,Encryption,我数据库中的数据是加密的。当我在gridview上打印它时,它是这样的: 在我的标记上: <asp:GridView ID="GridView1" SelectMethod="GetParents" ... > <Columns> <asp:TemplateField HeaderText="LastName" SortExpression="LastName"> <ItemTemplate>

我数据库中的数据是加密的。当我在gridview上打印它时,它是这样的:

在我的标记上:

 <asp:GridView ID="GridView1" SelectMethod="GetParents" ... >
     <Columns>
      <asp:TemplateField HeaderText="LastName" SortExpression="LastName">
        <ItemTemplate>
            <asp:Label Text='<%# GetDecrypted((string)Eval("LastName"))%>'
                runat="server" />
        </ItemTemplate>
      </asp:TemplateField>
     </Columns>
</asp:GridView>
这是我的选择方法

public IQueryable<Parent> GetParents()
    {
        InfantRecordContext db = new InfantRecordContext();
        int id = int.Parse(Session["DoctorID"].ToString());
        return db.Parent.Where(p => p.DoctorID == id);
    }
publicIQueryable GetParents()
{
InfantRecordContext db=新的InfantRecordContext();
int id=int.Parse(会话[“DoctorID”].ToString());
返回db.Parent.Where(p=>p.DoctorID==id);
}
问题是,当我对列进行排序时,它会对加密的数据进行排序,而不是对解密的数据进行排序,有没有一种方法可以对gridview上显示的解密数据进行排序


或者有没有一种方法可以在排序之前解密字段?

您只需在事件中解密,然后手动执行排序

网格视图实际上应该包含:
GridView.Sorting
事件。目的:

当用于对列进行排序的超链接被选中时,将引发排序事件 单击,但在
GridView
控件处理排序操作之前。 这使您能够提供执行 自定义例程,如取消排序操作,只要 事件发生。一个
GridViewSortEventArgs
对象被传递到 事件处理方法,它使您能够确定排序 列和的表达式,以指示选择操作 应该取消。要取消选择操作,请设置“取消”
GridViewSortEventArgs
对象的属性为true

代码示例如下所示:

  protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)
  {

    //Retrieve the table from the session object.
    DataTable dt = Session["TaskTable"] as DataTable;

    if (dt != null)
    {

      //Sort the data.
      dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
      TaskGridView.DataSource = Session["TaskTable"];
      TaskGridView.DataBind();
    }

  }

  private string GetSortDirection(string column)
  {

    // By default, set the sort direction to ascending.
    string sortDirection = "ASC";

    // Retrieve the last column that was sorted.
    string sortExpression = ViewState["SortExpression"] as string;

    if (sortExpression != null)
    {
      // Check if the same column is being sorted.
      // Otherwise, the default value can be returned.
      if (sortExpression == column)
      {
        string lastDirection = ViewState["SortDirection"] as string;
        if ((lastDirection != null) && (lastDirection == "ASC"))
        {
          sortDirection = "DESC";
        }
      }
    }

    // Save new values in ViewState.
    ViewState["SortDirection"] = sortDirection;
    ViewState["SortExpression"] = column;

    return sortDirection;
  }

将查询存储到列表中。在存储时,对必要的值进行解密。然后将列表返回为

list.AsQueryable();

使其与gridview兼容。

为什么不在绑定到gridview之前对其进行解密?您将使用什么作为gridview的数据源?嗨@mason,我更新了我的帖子,如果您能在绑定到gridview之前发表您关于解密的想法,我将不胜感激。我知道如何使用select all返回,但我不知道如何逐个选择字段并首先解密它们。谢谢大家!@你好!我更新了我的帖子并添加了我用于选择方法的部分,谢谢!我编辑了这个问题,让它更清楚地说明你具体需要做什么。谢谢!我试试这个!
list.AsQueryable();