What is DataBinder.Eval in ASP.Net

Last Reply on Nov 01, 2012 01:58 AM By vinayak

Posted on Oct 31, 2012 03:22 AM

i have a doubt in this line..

can u tell me what this line will do the operation

<%#"default.aspx?UserId="+DataBinder.Eval(Container.DataItem,"UserId") %>'> <%#Eval("UserName") %>



Posted on Nov 01, 2012 01:58 AM

In Design add GridView like,

<asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="false">
        <Columns>        
         <asp:TemplateField HeaderText = "EmpDetails">
                <ItemTemplate>
                    <%#DataBinder.Eval(Container.DataItem, "EmpCode")%>
                    <%#DataBinder.Eval(Container.DataItem, "Name")%>
                    <%#DataBinder.Eval(Container.DataItem, "Gender")%>
                </ItemTemplate>
            </asp:TemplateField>                             
        </Columns>
    </asp:GridView>

and in code,
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add("EmpCode"); dt.Columns.Add("Name"); dt.Columns.Add("Gender"); dt.Rows.Add("E1", "A", "M"); dt.Rows.Add("E2", "B", "F"); dt.Rows.Add("E3", "C", "M"); gvTest.DataSource = dt; gvTest.DataBind(); } }