using template columns

  • Thread starter Brett Wesoloski
  • Start date
B

Brett Wesoloski

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(Control control)
at System.Web.UI.WebControls.Button.AddAttributesToRender(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.BaseDataList.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter 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
 
B

Brett Wesoloski

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 said:
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(Control control)
at System.Web.UI.WebControls.Button.AddAttributesToRender(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.BaseDataList.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter 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
 

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

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top