473,785 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using template columns

I am new to using template columns. I am just trying to create a data grid
with a bound column and another column with a imagebutton in it.

What I have always done in the past was to then create a datatable and bind
that to the datagrid.
Where is my code to bind the grid to the datatable.
DataTable dt = new DataTable();
dt.Columns.Add( "FundDescriptio n");
//dt.Columns.Add( "F");

PlanAssetCollec tion planAssets = PlanFactory.Get PlanAssets(1845 4);
foreach (PlanAsset planAsset in planAssets)
{
if (planAsset.Fund InfoLink != String.Empty)
{
DataRow dr = dt.NewRow();
dr["FundDescriptio n"] = planAsset.FundD escription;
//dr["F"] = "F";

dt.Rows.Add(dr) ;
}

}
dgInvestmentInf o.DataSource = dt;
dgInvestmentInf o.DataBind();
Hear is the asp code to create the template columns.

<asp:DataGrid id="dgInvestmen tInfo" runat="server"
AutoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn HeaderText="Fun d Desc">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<font size="4">
<%# DataBinder.Eval (Container.Data Item, "FundDescriptio n") %>
</font>
/ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="F">
<ItemTemplate >
<asp:ImageButto n id="F" onclick="F_Clic k" runat="server"
ImageUrl="~imag es/signin.gif"></asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

I have also tried to add the CommandArgument to the asp:ImageButton
CommandArgument ='<%# DataBinder.Eval (Container.Data Item, "F") %>'
CommandName="F" to the asp code and then add the extra column to the
datatable. Didn't work.
This is the error I get when I run the code.

Error: Control '_ctl0_dgInvest mentInfo__ctl2_ btnDel' of type 'Button' must
be placed inside a form tag with runat=server.
at System.Web.UI.P age.VerifyRende ringInServerFor m(Control control)
at System.Web.UI.W ebControls.Butt on.AddAttribute sToRender(HtmlT extWriter
writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderBe ginTag(HtmlText Writer
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.Tabl eCell.RenderCon tents(HtmlTextW riter
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.W ebControls.Tabl e.RenderContent s(HtmlTextWrite r writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.Base DataList.Render (HtmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.P age.ProcessRequ estMain()

Now if I just add another bound coulmn to the grid I can get it to work
fine. It just seems to be when I add a imagebutton or any type of button
for that matter.

TIA,
Brett
Jan 8 '07 #1
1 2121
Ok I also should mention that I am trying to do all this in a user control
which I place on a from. So the form does have the form tag with the runat =
server.

"Brett Wesoloski" <br*********@pa i.comwrote in message
news:eZ******** *****@TK2MSFTNG P04.phx.gbl...
>I am new to using template columns. I am just trying to create a data grid
with a bound column and another column with a imagebutton in it.

What I have always done in the past was to then create a datatable and
bind
that to the datagrid.
Where is my code to bind the grid to the datatable.
DataTable dt = new DataTable();
dt.Columns.Add( "FundDescriptio n");
//dt.Columns.Add( "F");

PlanAssetCollec tion planAssets = PlanFactory.Get PlanAssets(1845 4);
foreach (PlanAsset planAsset in planAssets)
{
if (planAsset.Fund InfoLink != String.Empty)
{
DataRow dr = dt.NewRow();
dr["FundDescriptio n"] = planAsset.FundD escription;
//dr["F"] = "F";

dt.Rows.Add(dr) ;
}

}
dgInvestmentInf o.DataSource = dt;
dgInvestmentInf o.DataBind();
Hear is the asp code to create the template columns.

<asp:DataGrid id="dgInvestmen tInfo" runat="server"
AutoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn HeaderText="Fun d Desc">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<font size="4">
<%# DataBinder.Eval (Container.Data Item, "FundDescriptio n") %>
</font>
/ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="F">
<ItemTemplate >
<asp:ImageButto n id="F" onclick="F_Clic k" runat="server"
ImageUrl="~imag es/signin.gif"></asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

I have also tried to add the CommandArgument to the asp:ImageButton
CommandArgument ='<%# DataBinder.Eval (Container.Data Item, "F") %>'
CommandName="F" to the asp code and then add the extra column to the
datatable. Didn't work.
This is the error I get when I run the code.

Error: Control '_ctl0_dgInvest mentInfo__ctl2_ btnDel' of type 'Button' must
be placed inside a form tag with runat=server.
at System.Web.UI.P age.VerifyRende ringInServerFor m(Control control)
at System.Web.UI.W ebControls.Butt on.AddAttribute sToRender(HtmlT extWriter
writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderBe ginTag(HtmlText Writer
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.Tabl eCell.RenderCon tents(HtmlTextW riter
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.W ebControls.Tabl e.RenderContent s(HtmlTextWrite r writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.Base DataList.Render (HtmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.W ebControls.WebC ontrol.RenderCo ntents(HtmlText Writer
writer)
at System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
at System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
at System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
at System.Web.UI.P age.ProcessRequ estMain()

Now if I just add another bound coulmn to the grid I can get it to work
fine. It just seems to be when I add a imagebutton or any type of button
for that matter.

TIA,
Brett


Jan 8 '07 #2

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

Similar topics

6
2323
by: Alex | last post by:
I've a problem with following simple code (not really usefull): //--------------------------------------------------------------------------- #pragma hdrstop #include "stdio.h" #include <iostream> enum eTest1{et1_1, et1_2} e1; enum eTest2{et2_1, et2_2} e2; class ImageBase {
5
2314
by: catch | last post by:
Hi, Suppose I have a table something like: name (VARCHAR(64)) age (INT) quotation (TEXT) ================================================= Donald Trump 50 I am rich Bugs Bunny 26 What's up doc ...
4
5408
by: | last post by:
I have a datagrid with a template column that has a hyperlink and a label. The hyperlink text is bound to Title from my dataset and the label text is bound to Author in the dataset. The grid displays with the template columns showing the Title and the Author from the first row in all rows. The other none template columns are fine. Obviously I am not understanding something here. What am I missing????? -- Barry Fitzgerald
2
4554
by: Nicole | last post by:
I am creating template columns programmatically. I have read the msdn article on this and I'm so close. Article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingwebservercontroltemplatesprogrammatically.asp I have narrowed down the problem comes in when the _DataBinding handler is called and the literal text is being assigned, but I can't figure out beyond that. The main problem is that...
2
1435
by: Suma | last post by:
I have a problem with editable datagrid and was hoping if anyone could help me. Please help me if possible. I have an editable datagrid, whose column count I don’t know until runtime. I am sure of 3 columns Id,Name and Description. But there also might be more. So I add these 3 columns and an editcommandbutton and deletecommnadbutton at design time. Then during runtime I insert my other columns that I need, in between
1
1455
by: louise raisbeck | last post by:
This sounds complicated but bear with me. I have a datagrid. It is dynamic in that, i dont know how many columns i will have until the dataset is back so i have to build the datagrid dynamically. I know there will be at least one column required however, so I have put into my aspx a template column with a checkbox in it. Then for the number of columns in my dataset more than 1 I want to copy that templatecolumn and duplicate it for the...
3
13754
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
0
1126
by: shai.halevi | last post by:
I'm looking for a simple template with the following property: I want to have in the resulting page something like this (say): <div> This is some text that never changes: ]] This is some more text that never changes </div> The crux is that if the calling code never initializes the variable,
1
1946
by: neobonzi | last post by:
Hello! I'm dynamically creating a GridView bound to a datatable using custom template columns using the following method: protected void ShowGrid(DataTable dt) { int i; int j; for( i = 0; i < dt.Columns.Count; i++) {
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.