SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[fruit](
[id] [int] IDENTITY(1,1) NOT NULL,
[fruit_type] [int] NULL,
[fruit_img] [varchar](50) NULL,
CONSTRAINT [PK_fruit] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[fruit] ON
GO
INSERT [dbo].[fruit] ([id], [fruit_type], [fruit_img]) VALUES (2, 2, N'orange.jpg')
GO
INSERT [dbo].[fruit] ([id], [fruit_type], [fruit_img]) VALUES (3, 2, N'orange2.jpg')
GO
INSERT [dbo].[fruit] ([id], [fruit_type], [fruit_img]) VALUES (4, 1, N'mango.jpg')
GO
SET IDENTITY_INSERT [dbo].[fruit] OFF
GO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Text;
using System.IO;
using System.Globalization;
using System.Drawing.Imaging;
using System.Net.Mail;
using System.Net;
using System.Configuration;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
static string constr = ConfigurationManager.ConnectionStrings["lineStod"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
MainClass mc = new MainClass();
SqlConnection cn;
protected void Page_Load(object sender, EventArgs e)
{
cn = mc.sdbclink();
if (!IsPostBack)
{
BindDatalist();
}
}
private void BindDatalist()
{
try
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
SqlCommand cmdg1 = new SqlCommand("SELECT * FROM fruit", cn);
SqlDataAdapter da = new SqlDataAdapter(cmdg1);
DataSet ds = new DataSet();
da.Fill(ds, "fruit");
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
catch (Exception ex)
{
lbldisplay.Text = ex.Message.ToString();
}
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
function myFunction(row) {
var isValid = row == "2" ? true : false;
if (isValid) {
var customers = document.getElementById("test");
$.each(customers, function () {
document.getElementById("test").style.opacity = "0.1";
});
}
else {
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<%-- <asp:LinkButton ID="fruit_type" runat="server" OnClientClick="return myFunction(2)" Style="color: black;">Mango</asp:LinkButton>--%>
<a href="javascript:myFunction('2')">Orange</a>
<asp:DataList ID="DataList1" runat="server" DataKeyField="id" RepeatColumns = "4">
<ItemTemplate>
<asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("fruit_type") %>' />
<div class="cbp-item All" id="test">
<div class="cbp-caption-defaultWrap">
<img id="imgfruit" src='<%# string.Format("DataFiles/fruit/{0}", Eval("fruit_img")) %>' style="width:309px;height:231px;" />
</div>
</div>
</ItemTemplate>
</asp:DataList>
<asp:Label ID="lbldisplay" runat="server" ForeColor="Red"></asp:Label>
</asp:Content>
this is page details i want orange anchor tag is click using javascript change the opacity of fruit_type=2 from 0.1 inside datalist of all type 2