Tyler Miranda
Tyler Miranda

Reputation: 433

getting databind value in code behind

I'm trying to figure out how to get this value in the code behind. Any way to do this?

returned <%# DataBinder.Eval(Container.DataItem, "PagesFound")%> results. Showing results 1

Its part of datalist, and when I try to get the count from the datalist it isn't correct. meaning if it the value from the databinder.eval above is "7", the item count from the datalist will show 2.

Upvotes: 2

Views: 1522

Answers (2)

Aristos
Aristos

Reputation: 66641

You call the function this way

<asp:TemplateField HeaderText="Header Title" >
   <ItemTemplate ><%#GetYourData(Container.DataItem)%></ItemTemplate>
</asp:TemplateField>                

and the code behind.

protected string GetYourData(object oItem)
{
   return DataBinder.Eval(oItem, "PagesFound").ToString();
}

Upvotes: 2

codeandcloud
codeandcloud

Reputation: 55210

An idea will be to put the PagesFound in a HiddenField inside the DataList and then using FindControl on that.

Upvotes: 0

Related Questions