I have this GridView that I’m trying to bind data to and I need to create a new class with all my properties and display them in the Grid. Is this supposed to be a list collection because I tried a list but the Grid wasn’t able to find the names in the list.
I usually don’t deal with collections. So, I’m not very familiar with it. I just need some guidance on how this should be. I know I need a class for my collection and my properties are strings.
//This is where I am stuck, not sure how to set these and put these in a list.
public class Product
{
string Title;
string SmallImage;
}
<form id="ResultsForm" runat="server">
<div id="SearchBox">
<asp:TextBox ID="SearchBoxText" runat="server" Height="20px" Width="400px"></asp:TextBox>
<asp:Button ID="SearchButton" runat="server" Height="30px" Width="100px" Text="Search" OnClick="SearchButton_Click" />
</div>
<div id="ResultsTable">
<asp:GridView runat="server" ID="myGrid"
OnRowCommand="MyGrid_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img src='<%#Eval("SmallImage") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<div>Title: <%#Eval("Title") %> </div>
<div>Weight: <%#Eval("Weight") %> </div>
<asp:Button runat="server" ID="GetOfferButton" CommandArgument='<%#Eval("OfferID") %>'></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
1) Create class in separate file… like Product.cs
2) In your aspx.cs