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.
<aspataGrid 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>
</aspataGrid>
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
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.
<aspataGrid 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>
</aspataGrid>
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