473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

creating datagrid with code

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>
Nov 19 '05 #1
1 1265
Hi,

you would need to implement a class describing the template. See:

Implementing Dynamic ItemTemplates
http://www.tripleasp.net/tutorial.aspx?NavID=27

Second way it to declare template(s) in user controls and use
Page.LoadTemplate to load it from UC.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"David C" <pr********@yahoo.com> wrote in message
news:Xb*******************@twister.socal.rr.com...
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>

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephen | last post by:
I have a really annoying problem with a datagrid. I have an application which populates a datagrid on the onclick event of a button. The datagrid is bound to an ArrayList which holds the values. ...
0
by: Vilmar Brazão de Oliveira | last post by:
Hi, I am having err when creating link to each line of grid at LINE 38. My objective in asp.net is: each line can be linked to page with your parameters as VB 5/6, Delphi 5/6/7, etc.... See the...
3
by: Bad_Kid | last post by:
How can I dynamicly create a datagrid? (first I read a datatable from a database, see how many atributes does it have (n) and then build a datagrid with n columns...)??? (c#, asp.net)
4
by: Shiju Poyilil | last post by:
Hello EveryBody, I have a dropdownlist with some values as .net server controls & a button , on clicking a button i need to generate the choosen contorl dynamically. I am giving a small glimpse...
5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
4
by: Jeff | last post by:
I am stuck on trying to generate two columns headers for a datagrid on form load. I can use a datatable as the datasource and get the results I want, but I want to set different column widths and...
1
by: Marcel Hug | last post by:
Hi NG ! I have already written a task about MVC and I tried to get the best informations together. I would like to implement the MVC pattern and it work on the way I did it. At first i know the...
0
by: Ian | last post by:
Hi I have used the following code to essentially late bind an EditCommandColumn to my datagrid in ASP.NET. EditCommandColumn ec = new EditCommandColumn(); ec.ButtonType =...
5
by: tshad | last post by:
I found I can create Template columns dynamically - as long as I don't use objects that need onclick events, such as a LinkButton. Textboxes and Labels work fine. I create the Template columns...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.