By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

Using template columns

P: n/a
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("FundDescription");
//dt.Columns.Add("F");

PlanAssetCollection planAssets = PlanFactory.GetPlanAssets(18454);
foreach (PlanAsset planAsset in planAssets)
{
if (planAsset.FundInfoLink != String.Empty)
{
DataRow dr = dt.NewRow();
dr["FundDescription"] = planAsset.FundDescription;
//dr["F"] = "F";

dt.Rows.Add(dr);
}

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

<asp:DataGrid id="dgInvestmentInfo" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Fund Desc">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<font size="4">
<%# DataBinder.Eval(Container.DataItem, "FundDescription") %>
</font>
/ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="F">
<ItemTemplate>
<asp:ImageButton id="F" onclick="F_Click" runat="server"
ImageUrl="~images/signin.gif"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

I have also tried to add the CommandArgument to the asp:ImageButton
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "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_dgInvestmentInfo__ctl2_btnDel' of type 'Button' must
be placed inside a form tag with runat=server.
at System.Web.UI.Page.VerifyRenderingInServerForm(Con trol control)
at System.Web.UI.WebControls.Button.AddAttributesToRe nder(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.TableCell.RenderContents (HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.WebControls.Table.RenderContents(Htm lTextWriter writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.BaseDataList.Render(Html TextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain()

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
Share this Question
Share on Google+
1 Reply


P: n/a
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*********@pai.comwrote in message
news:eZ*************@TK2MSFTNGP04.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("FundDescription");
//dt.Columns.Add("F");

PlanAssetCollection planAssets = PlanFactory.GetPlanAssets(18454);
foreach (PlanAsset planAsset in planAssets)
{
if (planAsset.FundInfoLink != String.Empty)
{
DataRow dr = dt.NewRow();
dr["FundDescription"] = planAsset.FundDescription;
//dr["F"] = "F";

dt.Rows.Add(dr);
}

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

<asp:DataGrid id="dgInvestmentInfo" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Fund Desc">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<font size="4">
<%# DataBinder.Eval(Container.DataItem, "FundDescription") %>
</font>
/ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="F">
<ItemTemplate>
<asp:ImageButton id="F" onclick="F_Click" runat="server"
ImageUrl="~images/signin.gif"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

I have also tried to add the CommandArgument to the asp:ImageButton
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "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_dgInvestmentInfo__ctl2_btnDel' of type 'Button' must
be placed inside a form tag with runat=server.
at System.Web.UI.Page.VerifyRenderingInServerForm(Con trol control)
at System.Web.UI.WebControls.Button.AddAttributesToRe nder(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.TableCell.RenderContents (HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.WebControls.Table.RenderContents(Htm lTextWriter writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.BaseDataList.Render(Html TextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain()

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 discussion thread is closed

Replies have been disabled for this discussion.