I am trying to access a url stored in a database to display an image using asp image control based on user selection. When user selects, I would like image displayed.
The column name where the url is stored is "ImgLnk"
So I am trying this code:
<asp:Image ID="image1" runat="server" ImageUrl="ImgLnk" Height="100px" Width="100px" />
And my code behind:
string strConnectionString = ConfigurationManager.ConnectionStrings[""].ConnectionString;
string strSelect = "SELECT ImgLnk FROM Business WHERE ImgLnk = @ImgLnk";
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = strConnectionString;
SqlCommand cmdCustomerDetails = new SqlCommand();
cmdCustomerDetails.Connection = sqlCon;
cmdCustomerDetails.CommandType = System.Data.CommandType.Text;
cmdCustomerDetails.CommandText = strSelect;
//Create DataReader to read the record
SqlDataReader dReader = cmdCustomerDetails.ExecuteReader();
GridView2.DataSource = dReader;
image1.ImageUrl = HttpUtility.UrlEncode(dReader["ImgLnk"].ToString());
I do not know what else to try. Thanks for help code masters.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)