2013-04-24 29 views
3

我使用Objectdatasource填充gridview。在gridview中,其中一列是在數據庫中加密的值。我想在gridview中加載列的解密值。asp.net中的Objectdatasource

這裏是GridView和ObjectDataSource控件

<asp:GridView ID="GridView1" SkinID="GridView" runat="server" Width="100%" AutoGenerateColumns="False" 
          AllowPaging="True" PageSize="10" DataSourceID="ObjectDataSource1" AllowSorting="True" 
          AlternatingRowStyle-BackColor="Silver" HeaderStyle-BackColor="#666666" HeaderStyle-ForeColor="White"> 
          <Columns> 
           <asp:HyperLinkField DataNavigateUrlFields="Taxi_Id" HeaderText="Edit" DataNavigateUrlFormatString="TaxiForm.aspx?ID={0}&E=1" 
            Text="Edit" /> 
           <asp:BoundField DataField="Taxi_Id" HeaderText="Taxi_Id" SortExpression="Driver_Id" 
            Visible="False" /> 
           <asp:BoundField DataField="MedallionNo" HeaderText="Medallion No" SortExpression="MeddallionNo" /> 
           <asp:BoundField DataField="Car_Brand_Name" HeaderText="Brand Name" SortExpression="Car_Brand_Name" /> 
           <asp:BoundField DataField="Car_Model_Name" HeaderText="Model Name" SortExpression="Car_Model_Name" /> 
           <asp:BoundField DataField="Car_Year" HeaderText="Year" SortExpression="Car_Year" />                
           <asp:BoundField DataField="Affiliation_Name" HeaderText="Affiliation" SortExpression="Affiliation_Name" /> 
           <asp:BoundField DataField="Mileage" HeaderText="Mileage" SortExpression="Mileage" /> 
           <asp:BoundField DataField="Taxi_Company_Garage_Name" HeaderText="PickUp Location" SortExpression="Taxi_Company_Garage_Name" />         
           <asp:HyperLinkField DataNavigateUrlFields="Taxi_Id" HeaderText="Shift Rate" DataNavigateUrlFormatString="TaxiShiftRateList.aspx?ID={0}&E=1" Text="View Shift Rate" /> 
          </Columns> 
         </asp:GridView> 


<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
          SelectMethod="Owner_GetAll" TypeName="TMS.TaxiObj" > 
          <DeleteParameters> 
           <asp:Parameter Name="Driver_Id" Type="Int32" /> 
          </DeleteParameters> 
          <SelectParameters> 
           <asp:ControlParameter ControlID="txtMedallionNo" Name="MedallionNo" PropertyName="Text" 
            Type="String" DefaultValue="" /> 
           <asp:ControlParameter ControlID="ddlBrand" Name="Car_Brand_Id" PropertyName="Text" 
            Type="Int32" DefaultValue="-1" /> 
           <asp:ControlParameter ControlID="ddlModel" Name="Car_Model_Id" PropertyName="Text" 
            Type="Int32" DefaultValue="-1" /> 
           <asp:ControlParameter ControlID="ddlAffiliation" Name="Affiliation_Id" PropertyName="Text" 
            Type="Int32" DefaultValue="-1" /> 
          </SelectParameters> 
         </asp:ObjectDataSource> 
+1

什麼是您所遇到的問題或錯誤? – Josh 2013-04-24 15:25:50

+0

我不知道如何解密數據庫中的加密值並將解密值映射到gridview – user2235775 2013-04-24 15:29:31

回答

0

與標籤的模板列轉換你的專欄。

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"> 
    <Columns> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <asp:Label runat="server" Id="lbl"></asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

寄存器到GridViewOnRowDataBoundEvent。 在事件處理程序中解密該值並相應地設置標籤文本。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    Label lbl = e.Row.FindControl("lbl") as Label; 
    if (lbl != null) { 
     var encrypted = DataBinder.Eval(e.Row.DataItem, "EncryptedColumn"); 
     string decrypted = Decrypt(encrypted); 
     lbl.Text = decrypted; 
    } 
} 
+0

Thanq問題解決..... :) – user2235775 2013-04-25 11:49:22

0
<asp:TemplateField HeaderText="SomeField" SortExpression="SomeField"> 
    <ItemTemplate> 
     <asp:Label ID="Label1" runat="server" Text='<%# Decrypt(Eval("SomeField").ToString()) %>'></asp:Label> 
    </ItemTemplate> 
</asp:TemplateField> 
相關問題