Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've an object that contains a field called DevList which is defined like this

public List<string> DevList { get; set; }

I also defined a method called DisplayListOfDevelopers that is supposed to concatenate the list of developers and display it as a one string.

This is how I'm calling the method from aspx.

<asp:TemplateField HeaderText = "Developer(s)">
 <ItemTemplate>
   <asp:Label 
        ID="_lblDevList" 
        runat="server" 
        Text= '<%# DisplayListOfDevelopers(DevList) %>'>
   </asp:Label>
 </ItemTemplate>
</asp:TemplateField>

But, I'm getting this error: The name 'DevList' does not exist in the current context

Am I missing something?

EDIT

_gvStatus = ds;
_gvStatus.DataBind();

Where ds is just a list of objects that contains the DevList for now.

Thanks for helping

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
581 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming this is how your class looks:

public class MyItem
{
    public List<string> DevList { get; set; }
}

And that

ds = List<MyItem>();

Do this:

In your code-behind:

protected string DisplayListOfDevelopers(object _devList)
{
    //Cast your dev list into the correct object
}

In your markup:

<asp:TemplateField HeaderText = "Developer(s)">
 <ItemTemplate>
   <asp:Label 
        ID="_lblDevList" 
        runat="server" 
        Text= '<%# DisplayListOfDevelopers(Eval("DevList")) %>'>
   </asp:Label>
 </ItemTemplate>
</asp:TemplateField>

Just be sure to make the function in your code-behind is protected or public.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...