Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > using template columns

Reply
Thread Tools

using template columns

 
 
Brett Wesoloski
Guest
Posts: n/a
 
      01-08-2007
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(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


 
Reply With Quote
 
 
 
 
Brett Wesoloski
Guest
Posts: n/a
 
      01-08-2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>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(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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template columns and bound columns in gridview Vinki ASP .Net Web Controls 2 04-25-2007 04:22 PM
Read CSV - string Columns - Int columns =?Utf-8?B?YmVub2l0?= ASP .Net 0 05-08-2006 02:11 PM
database columns vs. gui columns and sorting ittay.dror@gmail.com Java 5 03-04-2006 10:48 AM
CSS columns problem - faux columns don't work henrybranson@hotmail.com HTML 4 11-24-2005 10:05 AM
convert rows to columns and columns to rows helpful sql ASP .Net 0 05-19-2005 06:03 PM



Advertisments