I have a data binding method to bind a gridview to the database.
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("select bookingId, bookingName, fprice from addCart");
SqlDataAdapter sda = new SqlDataAdapter();
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
con.Close();
}
As I had previously used a base64 encoding method to encode the bookingId and bookingName, the data displayed in the gridview shows only the encoded values. How do I add in a base64 decoding method such that it displays decoded value in the gridview?
How I used my encoding:
byte[] serviceEncode = System.Text.Encoding.Unicode.GetBytes(serviceLabel.Text);
sqlCmd.Parameters.AddWithValue("@bookingName", SqlDbType.VarChar).Value = Convert.ToBase64String(serviceEncode);
Database value: QgBpAGMAeQBjAGwAZQAmACMAMwAyADsA
I had previously used an html decoding method in my item template. I am wondering if there is any similar known method to decode using base64?
<ItemTemplate>
<asp:Label ID="Label1" runat="server" decoding="base64" Text='<%# HttpUtility.HtmlDecode(Eval("bookingName").ToString()) %>'></asp:Label>
</ItemTemplate>