Monday, 4 May 2015

What is the difference between <%#Eval%> or <%#Bind%> In a gridview

In a gridview, we can use <%#Eval%> or <%#Bind%> to output values from a database.
What is the difference between them?

EVal is one way binding, Bind is two way
If you bind a value using Eval, it is like a read only. You can only view the data.
If you bind a value using Bind, and if you do some change on the value
it will reflect on the database also



as they said Eval is one way and Bind is two way but one more important difference Bind must be assigned to a property of server side control (runat="server") while you can assign Eval to server side or client side control

<asp:ListView ID="listview1" runat="server">
    <ItemTemplate>
         <%--you can do this--%>
         <asp:Label ID="label1" runat="server" Text="<%#Bind('xx')  %>"></asp:Label>
         <%--you can do this--%>
         <asp:Label ID="label2" runat="server" Text="<%#Eval('xx')  %>"></asp:Label>
         <div>
         <%--WILL CAUSE AN ERROR--%>
             "<%#Bind('xx')  %>"
         <%--you can do this--%>
             "<%#Eval('xx')  %>"
         </div>
    </ItemTemplate>
</asp:ListView>

SQL Related Some Query

-- DEFAULT CONSTANT
SELECT * FROM sys.objects
WHERE  Type='D' and create_date >= '20150401'
--AND create_date < GETDATE()

-- FOREIGN KEY
SELECT * FROM sys.objects
WHERE  Type='F' and create_date >= '20150401'
--AND create_date < GETDATE()

-- SCALAR FUNCTION
SELECT * FROM sys.objects
WHERE Type='FN' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- INLINE TABLE VALUE FUNCTION
SELECT * FROM sys.objects
WHERE Type='IF' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- INTERNAL TABLE
SELECT * FROM sys.objects
WHERE Type='IT' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- PROCEDURE
SELECT * FROM sys.objects
WHERE Type='P' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- PRIMARY KEY
SELECT * FROM sys.objects
WHERE Type='PK' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- SEQUENCE OBJECT
SELECT * FROM sys.objects
WHERE  Type='SO' and create_date >= '20150401'
--AND create_date < GETDATE()

-- SERVICE QUEUE
SELECT * FROM sys.objects
WHERE Type='SQ' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- TABLE VALUED FUNCTION
SELECT * FROM sys.objects
WHERE Type='TF' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- TRIGGER
SELECT * FROM sys.objects
WHERE Type='TR' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- TYPE TABLE
SELECT * FROM sys.objects
WHERE Type='TT' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- USER TABLE
SELECT * FROM sys.objects
WHERE Type='U' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- UNIQUE CONSTANT
SELECT * FROM sys.objects
WHERE Type='U' and  create_date >= '20150401'
--AND create_date < GETDATE()

-- VIEW
SELECT * FROM sys.objects
WHERE Type='V' and  create_date >= '20150401'
--AND create_date < GETDATE()