Bind and Eval query

KaranGupta
KaranGupta used Ask the Experts™
on
Hi

I have read the difference between the Eval and Bind.

Eval - One way binding

Bind - Two Way binding

<asp:GridView ID="GridView2" runat="server"> 
        <Columns> 
            <asp:TemplateField> 
                <ItemTemplate> 
                    <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("name") %>'></asp:TextBox> 
                </ItemTemplate> 
            </asp:TemplateField> 
        </Columns> 
</asp:GridView>

Open in new window


And

<asp:GridView ID="GridView2" runat="server"> 
        <Columns> 
            <asp:TemplateField> 
                <ItemTemplate> 
                    <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("name") %>'></asp:TextBox> 
                </ItemTemplate> 
            </asp:TemplateField> 
        </Columns> 
    </asp:GridView>

Open in new window


gives the same result. Then how does these 2 things differ.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
One way binding - do this when your reading mainly
    - Read only

Two way binding - do this when your could possibly edit the records.
   - Read / Write
Dear!!!

you can see the example here

 <EditItemTemplate>
           <asp:TextBox ID="txteRowId" runat="server" Text='<%# Bind("Row_id") %' />                                                                            
  </EditItemTemplate>  
  <ItemTemplate>  
       <asp:TextBox ID="txtCRowId" runat="server" Text='<%# Eval("Row_id") %>' />  
  </ItemTemplate>  

 
Note - when your requirement is just to read i.e. only Itemtemplate then use "Eval"
           when your requirement is just to write i.e. only EditItemtemplate then use "Bind"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial