locked
Get Eval in code behind RRS feed

  • Question

  • User-492460945 posted

    Hi?

    I got struck at one point. Can any tell me how we can get Eval value from gridview in codebehind.

    <asp:TemplateField HeaderText="Task Name" HeaderStyle-Width="200px" ItemStyle-Width="200px">                                                            <ItemTemplate>
    <%#Eval("taskInfo") %>
    </ItemTemplate>
    </asp:TemplateField>

    I need <%#Eval("taskInfo")%> value in codebehind.. how?

    Tuesday, July 22, 2014 3:58 AM

Answers

  • User-1360095595 posted

    Well then you'll need to reference the specific cell: e.Row.Cells[NN].Text where NN is the cell in question.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 22, 2014 7:25 AM

All replies

  • User-760709272 posted

    Use the RowDataBoundEvent of the gridview and then access the data item

    http://stackoverflow.com/questions/2053470/how-to-get-the-entity-object-from-rowdatabound-in-a-entitydatasource-bound-gridv

    That gives you the gist, hard to get c# examples for this stuff but the code is fairly standard and easy to understand.

    Tuesday, July 22, 2014 4:34 AM
  • User489113254 posted

    you can use

    e.Row.DataItem

    or

    <asp:TemplateField HeaderText="Task Name" HeaderStyle-Width="200px" ItemStyle-Width="200px">                                                           
     <ItemTemplate>
         <asp:Label id="lb" runat="server"  Text = <%#Eval("taskInfo") %> />
        </ItemTemplate>
    </asp:TemplateField>
    
    and 
    
    ((Label)e.row.FindControl(lb)).Text
    

     

    Tuesday, July 22, 2014 7:13 AM
  • User-492460945 posted

    <asp:TemplateField HeaderText="Task Name" HeaderStyle-Width="200px" ItemStyle-Width="200px">                                                           
     <ItemTemplate>
         <asp:Label id="lb" runat="server"  Text = <%#Eval("taskInfo") %> />
        </ItemTemplate>
    </asp:TemplateField>
    
    and 
    
    ((Label)e.row.FindControl(lb)).Text

    Thanks for your reply..

    Well I can use label control.. but I need without any control actually..

    Tuesday, July 22, 2014 7:23 AM
  • User-1360095595 posted

    Well then you'll need to reference the specific cell: e.Row.Cells[NN].Text where NN is the cell in question.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 22, 2014 7:25 AM
  • User489113254 posted

    then try

    string val = DataBinder.Eval(e.Item.DataItem, "taskInfo").ToString();

    Tuesday, July 22, 2014 7:36 AM
  • User-492460945 posted

    Well then you'll need to reference the specific cell: e.Row.Cells[NN].Text where NN is the cell in question.

    Yes..This is working. Thankyou MetalAsp.Net!!

    Tuesday, July 22, 2014 9:19 AM