creating datagrid with code

D

David C

I am trying to dynamically create a datagrid with code that looks exactly
like what the asp tags show below. It has only one column and that column
is a template column with a link button control.

This is how far I was able to take this.

DataGrid dgRecords = new DataGrid();
dgRecords.DataKeyField = "RecordID";
dgRecords.AutoGenerateColumns = false;

TemplateColumn temcol = new TemplateColumn();

I know it's not very much. I just can't figure out how to have the embedded
link button control in the column. Thanks.

<asp:DataGrid id="dgRecords" runat="server" DataKeyField="RecordID"
AutoGenerateColumns="False"
Visible="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="lnkLink" Runat="server">
<%#DataBinder.Eval(Container.DataItem, "Entry")%>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top