Reputation: 1174
I have a gridview which contains template fields in which every template field contains a litreal control, and I want to bind that grid view with my DataSet, please look into the code to find more.
Code to create DataSet-
DataTable Record = new DataTable();
Record.Columns.Add("zerker");
DataRow dr = Record.NewRow();
dr["zerker"] = "SomeText";
Record.Rows.Add(dr);
gvCustomres.DataSource = Record;
gvCustomres.DataBind();
Code to create GridView-
<asp:GridView ID="gvCustomres" runat="server" PageSize="4" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="Zerker">
<ItemTemplate>
<asp:Literal ID="zerkername" runat="server"></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
Please help me to find correct way to do this. Thanks,
Upvotes: 0
Views: 4637
Reputation: 4892
Your code above is all right if you just want to bind
Column
"zerker" to yourgridiview
.
All you are missing is the Text Property
for your Literal
control.
<asp:Literal ID="zerkername" runat="server" Text='<%# Eval("zerker") %>'>
</asp:Literal>
Upvotes: 1